Skip to content

Commit 77e895e

Browse files
fix(test): ensure Migration indexes exist on per-worker DBs when migrations pre-warmed (#3561)
* fix(test): ensure Migration indexes exist on per-worker DBs when migrations pre-warmed When DEVKIT_MIGRATIONS_RAN=1 (set by globalSetup), bootstrap() skipped migrations.run() entirely — but jest workers operate on JEST_WORKER_ID-suffixed DBs that never had indexes created. The unique index on Migration.name was only present on the base DB, causing duplicate-rejection assertions (migrations.integration.tests.js) to fail on worker DBs. Fix: in the migrationsAlreadyRan branch, call migrations.ensureMigrationIndexes() (which delegates to Migration.syncIndexes()) to recreate the unique index on the worker DB without re-running the migration files themselves. Backported from trawl_node commit ce541f0f72d3 (trawl_node#1075). * fix(test): clarify ensureMigrationIndexes comment to cover --runInBand case
1 parent 478944d commit 77e895e

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lib/app.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ const bootstrap = async () => {
7676
process.env.NODE_ENV === 'test' && process.env.DEVKIT_MIGRATIONS_RAN === '1';
7777
if (!migrationsAlreadyRan) {
7878
await migrations.run();
79+
} else {
80+
// globalSetup already ran migrations on a DB that may differ from the one
81+
// this suite connects to (e.g. a per-worker DB identified by JEST_WORKER_ID,
82+
// or the same base DB when running with --runInBand). Ensure the unique
83+
// index on Migration.name exists in the currently-connected DB so
84+
// duplicate-rejection works correctly (e.g. migrations.integration.tests.js).
85+
// On the base DB this is a harmless no-op — indexes already exist after
86+
// globalSetup ran migrations.run().
87+
await migrations.ensureMigrationIndexes();
7988
}
8089
app = await startExpress();
8190
} catch (e) {

0 commit comments

Comments
 (0)