Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions supabase/migrations/20251006_complete_monolithic_setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2505,5 +2505,29 @@ BEGIN
END IF;
END $$;

-- ============================================================================
-- PART 11: LEGACY CLEANUP (#49 / #170)
-- ============================================================================
-- Pre-#49 leftovers from an old conflicting `00000000000000_rls_foundation.sql`
-- migration (since deleted): the legacy `profiles` / `audit_logs` tables and
-- the old `handle_new_user()` signup trigger function that fed them (plus its
-- `handle_updated_at()` helper + `profiles_updated_at` trigger). The canonical
-- schema uses `user_profiles` / `auth_audit_logs` written by
-- `create_user_profile()` (see PART 8 + the on_auth_user_created trigger).
--
-- A fresh install from this file never creates these objects, so this block is
-- ONLY to converge existing databases (prod) with a clean install. Verified
-- safe on prod 2026-07-04 by the schema-drift audit (#170): both tables held
-- ZERO real-user rows (audit_logs = 8263 legacy `user.signup` events, all
-- null/E2E; profiles = 16 E2E throwaways), no view/FK/canonical-function
-- referenced them, and handle_new_user was orphaned (no trigger fired it).
-- Dropping handle_new_user/handle_updated_at also clears their
-- function_search_path_mutable security-advisor flags.
DROP TRIGGER IF EXISTS profiles_updated_at ON public.profiles;
DROP TABLE IF EXISTS public.audit_logs CASCADE;
DROP TABLE IF EXISTS public.profiles CASCADE;
DROP FUNCTION IF EXISTS public.handle_new_user() CASCADE;
DROP FUNCTION IF EXISTS public.handle_updated_at() CASCADE;

-- Commit the transaction - everything succeeded
COMMIT;
9 changes: 9 additions & 0 deletions supabase/migrations/999_drop_all_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ DROP TABLE IF EXISTS user_connections CASCADE;
DROP TABLE IF EXISTS auth_audit_logs CASCADE;
DROP TABLE IF EXISTS user_profiles CASCADE;

-- Pre-#49 legacy leftovers (#170) — no-ops on a clean DB, dropped here so a
-- full teardown clears them too if run against an older database.
DROP TRIGGER IF EXISTS profiles_updated_at ON public.profiles;
DROP TABLE IF EXISTS audit_logs CASCADE;
DROP TABLE IF EXISTS profiles CASCADE;

-- Drop trigger on auth.users if exists
DROP TRIGGER IF EXISTS on_auth_user_created ON auth.users;

Expand All @@ -70,6 +76,9 @@ DROP FUNCTION IF EXISTS check_rate_limit(TEXT, TEXT, INET) CASCADE;
DROP FUNCTION IF EXISTS record_failed_attempt(TEXT, TEXT, INET) CASCADE;
DROP FUNCTION IF EXISTS update_conversation_timestamp() CASCADE;
DROP FUNCTION IF EXISTS assign_sequence_number() CASCADE;
-- Pre-#49 legacy signup-trigger functions (#170)
DROP FUNCTION IF EXISTS handle_new_user() CASCADE;
DROP FUNCTION IF EXISTS handle_updated_at() CASCADE;

-- =========================================
-- CLEANUP COMPLETE
Expand Down
Loading