fix: coordinated schema migration for audit findings 18-21, 37-39#199
Open
jakebromberg wants to merge 7 commits intomainfrom
Open
fix: coordinated schema migration for audit findings 18-21, 37-39#199jakebromberg wants to merge 7 commits intomainfrom
jakebromberg wants to merge 7 commits intomainfrom
Conversation
Combines seven schema fixes into a single migration (0026) to avoid ordering conflicts between individual PRs: - F18: shift_covers.schedule_id serial → integer (drop auto-increment on FK) - F19: flowsheet.play_order serial → integer (manually managed, not auto-inc) - F20: artist_library_crossreference add NOT NULL on both FK columns - F21: show_djs add unique constraint on (show_id, dj_id) - F37: anonymous_devices remove redundant .unique() (keep explicit uniqueIndex) - F38: add ON DELETE cascade/set-null rules to 15 FK relationships - F39: add withTimezone to all 14 wxyc_schema timestamp columns Timestamp conversions use AT TIME ZONE 'America/New_York' to preserve the intended wall-clock times from the station's local timezone. Co-authored-by: Cursor <cursoragent@cursor.com>
c20558f to
8e069f9
Compare
added 6 commits
February 27, 2026 10:22
play_order changed from serial to integer, requiring explicit values. Add getNextPlayOrder() helper that computes max(play_order)+1 per show. Use it in addTrack, startShow, endShow, and DJ join/leave notifications.
The 0024_anonymous_devices.sql migration file existed but had no corresponding journal entry, so drizzle-kit never executed it. The 0026_schema_audit_fixes migration then failed with "relation anonymous_devices does not exist" when trying to drop a constraint on the missing table. Add journal entry at idx 27 for 0024_anonymous_devices (before the schema audit fixes at idx 28) so the table is created first.
Use --abort-on-container-exit with docker compose up ci-db-init so that migration failures are caught immediately instead of silently continuing with an uninitialized database.
getNextPlayOrder() was scoped per-show (WHERE show_id = X), making play_order values non-globally-unique. Queries use ORDER BY play_order DESC globally, so the sequence must be monotonically increasing across all shows to preserve correct ordering.
… changes PostgreSQL cannot alter a column's type when a view depends on it. The migration now drops library_artist_view before converting library.add_date and library.last_modified to timestamptz, then recreates the view afterward.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Combines all 7 schema audit fixes into a single coordinated migration (
0026_schema_audit_fixes.sql) to avoid ordering conflicts between the individual schema PRs.Changes in
schema.tsshift_covers.schedule_id:serial→integer(FK should not auto-increment)flowsheet.play_order:serial→integer(manually managed by reorder ops)artist_library_crossreference: add.notNull()to both FK columnsshow_djs: adduniqueIndexon(show_id, dj_id)anonymous_devices.deviceId: remove redundant.unique()(keep explicituniqueIndex)onDelete: 'cascade'or'set null'{ withTimezone: true }Migration (
0026_schema_audit_fixes.sql)The migration is hand-crafted (not auto-generated) for safety:
DEFAULT nextval()and associated sequencesALTER COLUMN SET NOT NULL(verify no NULL rows exist first)ON DELETEruleALTER COLUMN TYPE timestamptz USING col AT TIME ZONE 'America/New_York'Relationship to individual PRs
The individual schema PRs (#192-#198) contain the schema.ts changes and unit tests but deliberately omit migrations. This PR provides the single migration that covers all of them. The individual PRs should be merged first (for their tests), then this PR merged last.
Pre-deployment checklist
artist_library_crossreference:SELECT count(*) FROM wxyc_schema.artist_library_crossreference WHERE artist_id IS NULL OR library_id IS NULL;show_djs:SELECT show_id, dj_id, count(*) FROM wxyc_schema.show_djs GROUP BY show_id, dj_id HAVING count(*) > 1;Test plan
schema.tstypechecks cleanlyMade with Cursor