Commit 30058cf
feat(database): reserve an ordinal band for package migrations, and defend it (#2430)
Guard rails ahead of the change that needs them. Nothing stages a package's
migrations yet; these are the four places that would renumber or delete one the
moment it existed, and installing them afterwards would ship a window in which
an application's own generator could delete a package's schema.
Migrations run in `readdirSync().sort()` order, so the leading ordinal IS the
run order. A package's tables carry foreign keys into the application's and
never the reverse, so a package's files must sort last. A reserved high band
rather than `max + 1`, because three ordinal computations would otherwise
invert that:
`nextMigrationNumber` maxes over every file, so one staged file would drag
every future application migration into the band behind it.
`historicalBoundary` takes the maximum among unmarked files, and a staged
file is unmarked, so `migrate:regenerate` would number the regenerated
application corpus above the package's.
`startAt` falls back to the maximum among preserved files, with the same
result by a different route.
The fourth is a delete rather than a renumber. `preprocessSqliteMigrations`
prunes duplicate create-table files by keeping the earliest filename, and a
package's ordinal is high by construction, so it loses that comparison against
anything the generator emitted for the same table. `regenerateMigrationCorpus`
is the other one: under `replaceUnmarked` or `onlyExistingTables` it deletes
every file regardless of marker. A package's migrations are not this corpus's
to rewrite, and the package would not put them back, since it ships them rather
than generating them.
The band is ten digits so lexicographic and numeric order still agree, which
is the property the whole scheme rests on and which a test pins.
All four guards are no-ops on a corpus with no band files, which is every
corpus today.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>1 parent d2cbc37 commit 30058cf
4 files changed
Lines changed: 111 additions & 5 deletions
File tree
- storage/framework/core/database
- src
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
711 | 712 | | |
712 | 713 | | |
713 | 714 | | |
714 | | - | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
715 | 720 | | |
716 | 721 | | |
717 | 722 | | |
| |||
3153 | 3158 | | |
3154 | 3159 | | |
3155 | 3160 | | |
3156 | | - | |
| 3161 | + | |
| 3162 | + | |
| 3163 | + | |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
3157 | 3167 | | |
3158 | | - | |
| 3168 | + | |
| 3169 | + | |
3159 | 3170 | | |
3160 | 3171 | | |
3161 | 3172 | | |
| |||
3205 | 3216 | | |
3206 | 3217 | | |
3207 | 3218 | | |
| 3219 | + | |
| 3220 | + | |
| 3221 | + | |
3208 | 3222 | | |
3209 | | - | |
| 3223 | + | |
3210 | 3224 | | |
3211 | 3225 | | |
3212 | 3226 | | |
3213 | | - | |
| 3227 | + | |
| 3228 | + | |
| 3229 | + | |
3214 | 3230 | | |
3215 | 3231 | | |
3216 | 3232 | | |
| |||
3559 | 3575 | | |
3560 | 3576 | | |
3561 | 3577 | | |
| 3578 | + | |
| 3579 | + | |
| 3580 | + | |
| 3581 | + | |
| 3582 | + | |
3562 | 3583 | | |
3563 | 3584 | | |
3564 | 3585 | | |
| |||
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
Lines changed: 50 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 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 | + | |
0 commit comments