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)
| Table | Purpose | Why Dead |
|---|---|---|
pages | Global page registry | v2 uses fact engine, not page tracking |
page_observations | Page-check snapshots | Part of v1 check pipeline |
page_change_events | Detected content changes | Part of v1 change detection |
page_change_summaries | AI summaries of changes | Part of v1 summary pipeline |
user_pages | User's tracked page library | v2 has no page library concept |
section_dom_mappings | DOM section tracking | v1 section-level monitoring |
page_title_history | Title change detection | v1 title tracking |
screenshot_captures | Page screenshot system | v1 visual diffing |
Notification System (3 tables)
| Table | Purpose | Why Dead |
|---|---|---|
sms_notification_pages | Per-page SMS toggles | v1 SMS notification system |
sms_delivery_log | SMS delivery audit trail | v1 SMS tracking |
notification_delivery_log | Unified email/SMS/push log | v1 delivery tracking |
User Features (3 tables)
| Table | Purpose | Why Dead |
|---|---|---|
personas | Audience personas for Discover | v1 persona system |
use_cases | Use case templates by persona | v1 use case system |
onboarding_state | Onboarding wizard progress | v1 onboarding flow |
Other (2 tables)
| Table | Purpose | Why Dead |
|---|---|---|
screen_avatars | Domain visual identifiers | v1 domain avatars |
type_metadata | Page/brand type metadata | v1 metadata system |
V1 Backup Schema
v1_backupschema 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 indrizzle/queries.tsplan_definitions,user_subscriptions— active subscription gating in web app (card detail, subscribe page)notification_preferences— active in/api/account/notificationsroutesystem_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
| File | Action |
|---|---|
packages/db/src/drizzle/schema.ts | Remove 16 table definitions + all relations |
packages/db/src/drizzle/queries.ts | Remove dead query functions for dropped tables |
packages/db/src/queries.ts | Remove Supabase-client functions for v1 tables |
packages/db/src/drizzle/feature-flags.ts | Remove admin queries referencing already-dropped v1 tables |
packages/db/src/client.ts | Remove v1 type definitions |
packages/db/src/__tests__/ | Remove test helpers referencing dropped tables |
packages/db/src/index.ts | Clean up re-exports |
| Generated types | Regenerate 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_backupschema dropped- Zero references to dropped tables in TypeScript code
bun run typecheckpassesbun run testpassesbun run migrations:checkpassesbun run cipasses