V1 Table Cleanup — Phase 8

Summary

Drop 16 remaining v1 tables, the v1_backup schema, and all associated dead code from the Eko codebase. This completes the migration from v1 page-tracking/notification/persona systems to the v2 fact engine architecture.

Context

Prior phases removed the core v1 infrastructure:

  • Phase 6 (migrations 0058-0060): Dropped tracked_urls, url_checks, url_changes, summaries, notification_deliveries
  • Phase 7 (migrations 0111-0113): Dropped 18 auxiliary tables (page tracking, brand proposals, correlation groups)

Phase 8 removes the remaining v1 tables that have no active v2 code paths.

Tables Being Dropped (16)

Page Tracking System (8 tables)

TablePurposeWhy Dead
pagesGlobal page registryv2 uses fact engine, not page tracking
page_observationsPage-check snapshotsPart of v1 check pipeline
page_change_eventsDetected content changesPart of v1 change detection
page_change_summariesAI summaries of changesPart of v1 summary pipeline
user_pagesUser's tracked page libraryv2 has no page library concept
section_dom_mappingsDOM section trackingv1 section-level monitoring
page_title_historyTitle change detectionv1 title tracking
screenshot_capturesPage screenshot systemv1 visual diffing

Notification System (3 tables)

TablePurposeWhy Dead
sms_notification_pagesPer-page SMS togglesv1 SMS notification system
sms_delivery_logSMS delivery audit trailv1 SMS tracking
notification_delivery_logUnified email/SMS/push logv1 delivery tracking

User Features (3 tables)

TablePurposeWhy Dead
personasAudience personas for Discoverv1 persona system
use_casesUse case templates by personav1 use case system
onboarding_stateOnboarding wizard progressv1 onboarding flow

Other (2 tables)

TablePurposeWhy Dead
screen_avatarsDomain visual identifiersv1 domain avatars
type_metadataPage/brand type metadatav1 metadata system

V1 Backup Schema

  • v1_backup schema containing 5 backup tables from Phase 6 (tracked_urls, url_checks, url_changes, summaries, notification_deliveries)
  • Created Feb 3, 2026 — now 14+ days old, well past rollback window

Tables Being Kept

These tables have active v2 code paths and must NOT be dropped:

  • brands, brand_categories, brand_category_assignments — active domain-brand linking in drizzle/queries.ts
  • plan_definitions, user_subscriptions — active subscription gating in web app (card detail, subscribe page)
  • notification_preferences — active in /api/account/notifications route
  • system_notifications — active in payment reminder, escalation, anniversary, and usage report crons
  • All v2 fact engine tables, profiles, domains, feature_flags, ai_model_tier_config

Approach

Single big-bang migration + code cleanup in one PR. Follows the pattern established by Phase 6 (0058-0060) and Phase 7 (0111-0113).

Migration (SQL)

FK-safe drop order (children before parents):

-- 1. Drop RLS policies on all 16 tables
-- 2. Drop functions used only by dropped tables
-- 3. Drop tables (children → parents):
--    section_dom_mappings, page_title_history, screenshot_captures
--    sms_delivery_log, notification_delivery_log, sms_notification_pages
--    page_change_summaries
--    page_change_events, page_observations
--    user_pages, pages
--    use_cases, personas
--    onboarding_state, screen_avatars, type_metadata
-- 4. DROP SCHEMA v1_backup CASCADE
-- 5. Drop orphaned enums (if any)

Code Cleanup

FileAction
packages/db/src/drizzle/schema.tsRemove 16 table definitions + all relations
packages/db/src/drizzle/queries.tsRemove dead query functions for dropped tables
packages/db/src/queries.tsRemove Supabase-client functions for v1 tables
packages/db/src/drizzle/feature-flags.tsRemove admin queries referencing already-dropped v1 tables
packages/db/src/client.tsRemove v1 type definitions
packages/db/src/__tests__/Remove test helpers referencing dropped tables
packages/db/src/index.tsClean up re-exports
Generated typesRegenerate via bun run db:types + bun run migrations:index

Also Clean Up

  • Orphaned v1 columns (tracked_url_id, url_check_id, url_change_id) in any remaining tables
  • Dead Supabase RPC functions (purge_url_content, mark_folder_urls_as_read, etc.)
  • Dead feature-flag admin queries that join against dropped v1 tables

Risks

  • Low risk: All tables being dropped have no active v2 code paths (verified via grep)
  • Rollback: If any table turns out to be needed, it can be recreated from the migration SQL or v1_backup (which is available until this migration runs)
  • Type errors: Code cleanup must be done atomically with the migration to avoid CI breakage

Success Criteria

  • All 16 tables dropped from database
  • v1_backup schema dropped
  • Zero references to dropped tables in TypeScript code
  • bun run typecheck passes
  • bun run test passes
  • bun run migrations:check passes
  • bun run ci passes