-
Notifications
You must be signed in to change notification settings - Fork 8
Review and fix database migration files #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This commit reorganizes the migration files to:
1. Make all queries safe for re-runs using IF NOT EXISTS/IF EXISTS patterns
2. Consolidate ALTER TABLE ADD COLUMN statements into original CREATE TABLE
3. Remove redundant migrations where tables/views were created then dropped
4. Remove migrations that were superseded by later ones
5. Renumber files for a clean sequential order (0001-0007)
Key changes:
- 0001: Merged all ALTER TABLE statements, wrapped CREATE TYPE in DO blocks
with EXCEPTION handling, removed materialized views that get dropped,
included final procedure version, added ON CONFLICT DO NOTHING to inserts
- 0002: Changed retention from 14 to 30 days, wrapped CREATE TYPE in DO blocks,
consolidated dashboard columns (teams, file_path, file_sha),
absorbed log_pattern and summary_pattern columns
- 0003: Unchanged (already safe)
- 0004: Rebuilt issues table without DEFERRABLE constraint (it was dropped anyway)
- 0005: Simplified teams table (removed redundant ALTER TABLE statements)
- 0006: Simplified github_sync (removed dashboard column ALTERs now in 0002)
- 0007: Unchanged (already safe)
Removed 14 redundant migration files that were either:
- Superseded by later migrations (0006, 0008, 0009)
- Created objects that were later dropped (0010, 0011, 0012)
- Already consolidated into earlier migrations (0013, 0014, 0015, 0016x2)
- Updating procedures already in 0001 (0018, 0021)
- Self-canceling operations (0019 added then removed columns)
PR Review: Database Migration ConsolidationOverall AssessmentThis migration consolidation is well-intentioned but has critical issues that need addressing before merging. The approach of making migrations idempotent and consolidating redundant files is sound, but there are bugs and missed optimizations. 🚨 Critical Issues1. Duplicate Index Creation (0001_create_monoscope_tables.sql:485)CREATE INDEX IF NOT EXISTS idx_apis_request_dumps_project_id_shape_hash ON apis.request_dumps(project_id, shape_hash, created_at DESC);
CREATE INDEX IF NOT EXISTS idx_apis_request_dumps_project_id_shape_hash ON apis.request_dumps(project_id, shape_hash, created_at DESC);Issue: Identical index created twice. This appears to be a merge artifact. 2. Missing
|
This commit reorganizes the migration files to:
Key changes:
Removed 14 redundant migration files that were either:
Closes #
How to test
Checklist