Commit 2427b79
fix(database): keep package models out of the migration generator's scope (#2428)
#2427 merged package models into the set the generator diffs, which is the
wrong side of the framework. A package owns its tables through the hand-written
SQL it ships, so a package model in scope means `generate:migrations` emits a
second CREATE TABLE for a table that already has one.
That duplicate is not inert. `preprocessSqliteMigrations` prunes duplicate
create-table files by keeping the earliest filename and calling
`deleteMigration()` on the rest, and once package migrations are staged into
the corpus the file it deletes can be the package's own. The plan's one
standing constraint on this work is that the generator must never delete a
package's migration, and the merged version walked straight into it.
Package models now report through `excludedTables` instead, which already
means "something else owns this table" and already feeds `protectedTables`, so
the generator knows the table exists and has no authority to drop it. That is
the same mechanism excluded framework defaults use, for the same reason.
The collision guards are unchanged and still worth having: two packages
shipping one model name, or a package shipping a model the framework owns,
both still stop the run.
Being a global is a separate question this does not answer. A package model is
still absent from `globalThis`, because that comes from the auto-import barrel
in @stacksjs/server rather than from here. That wiring is its own change, and
it carries its own hazards: discovery runs after the barrel is built on boot,
and the barrel's staleness check is mtime-based, which a package manager
preserving tarball mtimes will not trip.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>1 parent 93f55b3 commit 2427b79
2 files changed
Lines changed: 26 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
320 | | - | |
| 320 | + | |
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
352 | 358 | | |
353 | 359 | | |
354 | | - | |
355 | 360 | | |
356 | 361 | | |
357 | 362 | | |
358 | 363 | | |
359 | 364 | | |
360 | 365 | | |
361 | 366 | | |
362 | | - | |
363 | | - | |
364 | 367 | | |
365 | 368 | | |
366 | 369 | | |
367 | | - | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
368 | 374 | | |
369 | 375 | | |
370 | 376 | | |
| |||
Lines changed: 11 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
115 | | - | |
116 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
117 | 121 | | |
118 | 122 | | |
119 | 123 | | |
120 | 124 | | |
121 | | - | |
| 125 | + | |
122 | 126 | | |
123 | 127 | | |
124 | 128 | | |
| |||
154 | 158 | | |
155 | 159 | | |
156 | 160 | | |
157 | | - | |
| 161 | + | |
| 162 | + | |
158 | 163 | | |
159 | 164 | | |
160 | 165 | | |
| |||
0 commit comments