fix(quick-260613-ndv): reset familysync_test each run (truncate-all)
CREATE DATABASE IF NOT EXISTS reuses the prior run's data, so the test DB would itself accumulate users run-over-run (the same flaky list_shares fan-out the dev DB suffered). Truncate every table (except the drizzle migration ledger) at globalSetup start, FK-safe, so each run is a clean deterministic slate. Verified: familysync_test users 186 -> 93 across a run (reset, not doubled); dev familysync untouched at 3.
This commit is contained in:
@@ -105,9 +105,32 @@ export default async function setup(): Promise<void> {
|
||||
new URL('../src/db/migrations', import.meta.url),
|
||||
);
|
||||
await migrate(db, { migrationsFolder });
|
||||
|
||||
// Clean slate each run: truncate every table (except drizzle's migration
|
||||
// ledger) so familysync_test does NOT accumulate rows across runs. Without
|
||||
// this, CREATE DATABASE IF NOT EXISTS reuses the prior run's data and the
|
||||
// users table grows unbounded — re-creating the slow/flaky list_shares
|
||||
// fan-out the dev DB used to suffer, just in the test DB. FK-safe via the
|
||||
// session FOREIGN_KEY_CHECKS toggle (scoped to this one connection).
|
||||
const conn = await appPool.getConnection();
|
||||
try {
|
||||
const [rows] = await conn.query(
|
||||
`SELECT table_name AS t FROM information_schema.tables
|
||||
WHERE table_schema = ? AND table_type = 'BASE TABLE'
|
||||
AND table_name <> '__drizzle_migrations'`,
|
||||
[TEST_DB],
|
||||
);
|
||||
await conn.query('SET FOREIGN_KEY_CHECKS = 0');
|
||||
for (const { t } of rows as Array<{ t: string }>) {
|
||||
await conn.query(`TRUNCATE TABLE \`${t}\``);
|
||||
}
|
||||
await conn.query('SET FOREIGN_KEY_CHECKS = 1');
|
||||
} finally {
|
||||
conn.release();
|
||||
}
|
||||
} finally {
|
||||
await appPool.end();
|
||||
}
|
||||
|
||||
console.log('[global-setup] provisioned + migrated familysync_test');
|
||||
console.log('[global-setup] provisioned + migrated + reset familysync_test');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user