Commit 95091b2
committed
fix(migrations): address #1411 review — non-blocking FK validation + complete integration coverage
Apply five review findings on the #1126 FK ON DELETE drift fix:
1. Migration 0094 now uses ADD CONSTRAINT ... NOT VALID instead of a bare
ADD CONSTRAINT. The bare form would have taken AccessExclusiveLock on
flowsheet (~857k rows) for the full validation-scan duration, blocking
on-air DJ writes during deploy. NOT VALID makes the ADD metadata-only
and instant. Drizzle's migrator wraps the whole migration in one
transaction (drizzle-orm/pg-core/dialect.js:60), so an in-migration
VALIDATE would defeat the lock benefit — VALIDATE is documented as
an out-of-band operator step in the header instead. For these five
constraints the validation is effectively a no-op anyway: the
existing NO ACTION FK already kept the reference relation consistent,
and only the ON DELETE action is changing (forward-looking).
2. Integration spec now exercises all three ON DELETE actions in the fix
(flowsheet SET NULL, rotation CASCADE, reviews CASCADE) instead of
only the flowsheet SET NULL path. The previous spec ran two tests:
a static pg_constraint.confdeltype assertion plus a single behavioural
test. The behavioural test silently never ran because its library
INSERT omitted four NOT NULL columns (artist_id, genre_id, format_id,
code_number) and its flowsheet INSERT omitted play_order — so the
spec was a false green for the actual cascade/SET-NULL behaviour.
3. Spec now uses the shared getTestDb() pool + withRollback helper from
tests/utils/db.js instead of opening its own postgres() connection
and rolling back via a hand-written intentional-error idiom. Matches
the convention used by neighbouring specs (album-metadata-upsert,
enrichment-worker-claim, library-identity-backfill).
4. Inserts now use the seed_db.sql baseline rows (artist 1, genre 11,
format 1) to satisfy library's NOT NULL FK columns rather than
threading FK resolution through the test. Sequence-assigned ids land
at 7200+ (shape fixture sets library_id_seq to 7199), safely above
the explicit-id fixture range.
Local CI: lint, format:check, typecheck, test:unit all pass. Migration
dry-run not available locally (Docker daemon not running); will be
covered by CI's migrate-dryrun job since the change touches db-init paths.1 parent 3147e26 commit 95091b2
3 files changed
Lines changed: 153 additions & 59 deletions
Lines changed: 65 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
22 | 77 | | |
23 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
24 | 82 | | |
25 | 83 | | |
26 | 84 | | |
27 | | - | |
| 85 | + | |
28 | 86 | | |
29 | 87 | | |
30 | 88 | | |
31 | | - | |
| 89 | + | |
32 | 90 | | |
33 | 91 | | |
34 | 92 | | |
35 | | - | |
| 93 | + | |
36 | 94 | | |
37 | 95 | | |
38 | 96 | | |
39 | | - | |
| 97 | + | |
40 | 98 | | |
41 | 99 | | |
42 | 100 | | |
43 | | - | |
| 101 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
95 | 95 | | |
Lines changed: 87 additions & 51 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | | - | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | 28 | | |
40 | 29 | | |
41 | 30 | | |
| |||
46 | 35 | | |
47 | 36 | | |
48 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 53 | + | |
58 | 54 | | |
59 | 55 | | |
60 | 56 | | |
| |||
96 | 92 | | |
97 | 93 | | |
98 | 94 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
129 | 165 | | |
130 | 166 | | |
0 commit comments