fix: rebuild migration history as baseline so migrate works on prod
Squash the 13 historical migrations into one generated baseline whose journal entry reuses the original 0000 timestamp: the migrator skips it on every existing database (prod journal stuck at 0006) and applies it only on fresh ones. Parity with the old chain verified via pg_dump diff plus fresh/existing/prod-simulated drizzle-kit migrate runs. Historical files move to drizzle-history/pre-squash-2026-08/ for integration tests that exercise legacy migration behavior. Also repair db tests that already failed before this change: - raw SQL targeted users, but the table has always been "user" - membership recheck mocked legacy getAsset.albums instead of searchPhotos - audit rollback assertion walks drizzle's wrapped error cause chain - keyset index probe pinned to NULLS LAST ordering, removing a planner cost tie-break that flipped with index creation order
This commit is contained in:
1 parent
2949149170
commit
0b65fbba16
40 files changed
+2389
-128
No files matched your search
+10
-8
@@ -29,7 +29,9 @@ export type PostgresTestDatabase = {
|
||||
stop(): Promise<void>;
|
||||
};
|
||||
|
||||
export async function startPostgres({ through }: { through?: string } = {}): Promise<PostgresTestDatabase> {
|
||||
export async function startPostgres(
|
||||
{ through, migrationsDir }: { through?: string; migrationsDir?: string } = {},
|
||||
): Promise<PostgresTestDatabase> {
|
||||
const container = await new PostgreSqlContainer("postgres:17-alpine")
|
||||
.withDatabase("portal")
|
||||
.withUsername("portal")
|
||||
@@ -37,11 +39,11 @@ export async function startPostgres({ through }: { through?: string } = {}): Pro
|
||||
.start();
|
||||
const pool = new Pool({ connectionString: container.getConnectionUri() });
|
||||
|
||||
const migrationFiles = await listMigrationFiles();
|
||||
const migrationFiles = await listMigrationFiles(migrationsDir);
|
||||
const throughIndex = through ? migrationFiles.indexOf(through) : migrationFiles.length - 1;
|
||||
if (through && throughIndex < 0) throw new Error(`Unknown migration: ${through}`);
|
||||
let appliedMigrationCount = throughIndex + 1;
|
||||
await applyMigrationFiles(pool, migrationFiles.slice(0, appliedMigrationCount));
|
||||
await applyMigrationFiles(pool, migrationsDir, migrationFiles.slice(0, appliedMigrationCount));
|
||||
|
||||
const db = drizzle({ client: pool, schema });
|
||||
|
||||
@@ -64,7 +66,7 @@ export async function startPostgres({ through }: { through?: string } = {}): Pro
|
||||
});
|
||||
},
|
||||
async applyRemainingMigrations() {
|
||||
await applyMigrationFiles(pool, migrationFiles.slice(appliedMigrationCount));
|
||||
await applyMigrationFiles(pool, migrationsDir, migrationFiles.slice(appliedMigrationCount));
|
||||
appliedMigrationCount = migrationFiles.length;
|
||||
},
|
||||
async stop() {
|
||||
@@ -74,15 +76,15 @@ export async function startPostgres({ through }: { through?: string } = {}): Pro
|
||||
};
|
||||
}
|
||||
|
||||
async function listMigrationFiles() {
|
||||
const migrationDirectory = path.join(process.cwd(), "drizzle");
|
||||
async function listMigrationFiles(migrationsDir?: string) {
|
||||
const migrationDirectory = path.join(process.cwd(), migrationsDir ?? "drizzle");
|
||||
return (await readdir(migrationDirectory))
|
||||
.filter((file) => /^\d+_.*\.sql$/.test(file))
|
||||
.sort();
|
||||
}
|
||||
|
||||
async function applyMigrationFiles(pool: Pool, migrationFiles: string[]) {
|
||||
const migrationDirectory = path.join(process.cwd(), "drizzle");
|
||||
async function applyMigrationFiles(pool: Pool, migrationsDir: string | undefined, migrationFiles: string[]) {
|
||||
const migrationDirectory = path.join(process.cwd(), migrationsDir ?? "drizzle");
|
||||
for (const file of migrationFiles) {
|
||||
await pool.query(await readFile(path.join(migrationDirectory, file), "utf8"));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user