feat: add automated migrations to deployment pipeline #144
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Changes
Migration Testing Tools (New)
Added infrastructure to catch migration issues before production deployment:
lint-migrations.jsgenerate-rollback.mjsestimate-migration.mjscreate-schema-snapshot.mjsload-schema-snapshot.mjstest-migrations-snapshot.mjsLint Rules:
concurrent-index: Warns when CREATE INDEX misses CONCURRENTLYnot-null-no-default: Blocks ADD COLUMN NOT NULL without DEFAULTmissing-if-not-exists: Warns about missing idempotency guardsdangerous-ops: Blocks TRUNCATE, DROP TABLE without IF EXISTSCI Integration:
shared/npm Scripts:
Database Indexes
Added B-tree indexes to improve query performance:
flowsheetflowsheet_show_id_idxshow_idflowsheetflowsheet_album_id_idxalbum_idflowsheetflowsheet_rotation_id_idxrotation_idshow_djsshow_djs_show_id_dj_id_idx(show_id, dj_id)show_djsshow_djs_dj_id_idxdj_idbinsbins_dj_id_idxdj_idbinsbins_album_id_idxalbum_idDeployment Pipeline
Added migration jobs to the deployment workflow:
flowchart TB subgraph setup[Setup] A[Detect targets] --> B[Detect migration version] end subgraph build_phase[Build Phase] C[build-migrate] --> D[Build migrate:NNNN image] E[build] --> F[Build app images] end subgraph deploy_phase[Deploy Phase] G[migrate] --> H[Run migrations on EC2] H --> I[deploy] I --> J[Deploy app containers] end setup --> build_phase build_phase --> deploy_phaseMigration versioning: Images are tagged with the highest migration number (e.g.,
migrate:0028), providing traceability without manual version management.Migration Fixes
0024_anonymous_devices.sql→0028_anonymous_devices.sql0027_add-performance-indexes.sqlto contain only index definitionsNew Files
Dockerfile.migrate.github/actions/run-migrations/action.yml.github/workflows/migration-snapshot-test.ymlscripts/lint-migrations.jsscripts/generate-rollback.mjsscripts/estimate-migration.mjsscripts/*-snapshot.mjsshared/database/src/migrations/rollbacks/Test plan
Dockerfile.migratebuilds locallynpm run lint:migrationsto verify linter worksnpm run migration:estimate 0027_add-performance-indexes.sqlNotes
Migrations are already tested in CI via
init-db.mjswhich runsnpm run drizzle:migrateduring test environment setup. Any PR that modifiesshared/**(including migrations) triggers integration tests.