mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +00:00
fix(journey): make the source_assignment_id migration replay-safe
An unreleased migration has to survive being replayed on a schema where it already applied — installs skip releases, and a test rewinds a fully migrated database to the last released version to prove it. The bare ADD COLUMN threw "duplicate column name" on that replay, which took every migration test down with it. Guard the ALTER on pragma_table_info, and add `source_assignment_id IS NULL` to the backfill so a replay cannot re-resolve a row that has since followed its stop to another day. The trips e2e harness hand-builds a minimal journey_entries table rather than running migrations, so it needs the column spelled out too.
This commit is contained in:
@@ -4927,7 +4927,12 @@ function runMigrations(db: Database.Database): void {
|
||||
* already there instead of writing a duplicate beside it.
|
||||
*/
|
||||
() => {
|
||||
db.exec('ALTER TABLE journey_entries ADD COLUMN source_assignment_id INTEGER');
|
||||
const hasColumn = db
|
||||
.prepare("SELECT 1 FROM pragma_table_info('journey_entries') WHERE name = 'source_assignment_id'")
|
||||
.get();
|
||||
if (!hasColumn) db.exec('ALTER TABLE journey_entries ADD COLUMN source_assignment_id INTEGER');
|
||||
// `source_assignment_id IS NULL` keeps the replay from re-resolving a row that
|
||||
// has since followed its stop to another day.
|
||||
db.exec(`
|
||||
UPDATE journey_entries
|
||||
SET source_assignment_id = (
|
||||
@@ -4938,7 +4943,7 @@ function runMigrations(db: Database.Database): void {
|
||||
ORDER BY d.day_number ASC, d.date ASC, da.order_index ASC, da.id ASC
|
||||
LIMIT 1
|
||||
)
|
||||
WHERE source_place_id IS NOT NULL
|
||||
WHERE source_place_id IS NOT NULL AND source_assignment_id IS NULL
|
||||
`);
|
||||
db.exec(
|
||||
'CREATE INDEX IF NOT EXISTS idx_journey_entries_source_assignment ON journey_entries(source_place_id, source_assignment_id)',
|
||||
|
||||
Reference in New Issue
Block a user