From 9d87b3774036cdfdb9442fdf08a49321863ea89d Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Thu, 19 Mar 2026 22:54:25 -0700 Subject: [PATCH] =?UTF-8?q?feat:=20community=20tier=20schema=20=E2=80=94?= =?UTF-8?q?=20backup=20columns=20+=20benchmarks=20table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds user_id, email, config/analytics/retro snapshots, and backup versioning to installations. Creates community_benchmarks table with public read + service-role write RLS. Foundation for authenticated backup and community intelligence features. Co-Authored-By: Claude Opus 4.6 (1M context) --- supabase/migrations/002_community_tier.sql | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 supabase/migrations/002_community_tier.sql diff --git a/supabase/migrations/002_community_tier.sql b/supabase/migrations/002_community_tier.sql new file mode 100644 index 00000000..5bf0b789 --- /dev/null +++ b/supabase/migrations/002_community_tier.sql @@ -0,0 +1,39 @@ +-- gstack community tier schema +-- Adds authenticated backup, benchmarks, and email to the telemetry platform. + +-- Add columns to installations for backup + email + auth identity +ALTER TABLE installations ADD COLUMN user_id UUID; +ALTER TABLE installations ADD COLUMN email TEXT; +ALTER TABLE installations ADD COLUMN config_snapshot JSONB; +ALTER TABLE installations ADD COLUMN analytics_snapshot JSONB; +ALTER TABLE installations ADD COLUMN retro_history JSONB; +ALTER TABLE installations ADD COLUMN last_backup_at TIMESTAMPTZ; +ALTER TABLE installations ADD COLUMN backup_version INTEGER DEFAULT 0; + +-- RLS: authenticated users can read/write their own installation row +CREATE POLICY "auth_read_own" ON installations + FOR SELECT USING ( + (select auth.uid()) IS NOT NULL AND user_id = (select auth.uid()) + ); +CREATE POLICY "auth_write_own" ON installations + FOR INSERT WITH CHECK (user_id = (select auth.uid())); +CREATE POLICY "auth_update_own" ON installations + FOR UPDATE USING (user_id = (select auth.uid())) + WITH CHECK (user_id = (select auth.uid())); + +-- Community benchmarks (computed by edge function, cached) +CREATE TABLE community_benchmarks ( + skill TEXT PRIMARY KEY, + median_duration_s NUMERIC, + p25_duration_s NUMERIC, + p75_duration_s NUMERIC, + total_runs BIGINT, + success_rate NUMERIC, + updated_at TIMESTAMPTZ DEFAULT now() +); + +ALTER TABLE community_benchmarks ENABLE ROW LEVEL SECURITY; +CREATE POLICY "anon_select" ON community_benchmarks FOR SELECT USING (true); +CREATE POLICY "service_upsert" ON community_benchmarks FOR ALL + USING ((select auth.role()) = 'service_role') + WITH CHECK ((select auth.role()) = 'service_role');