-
Notifications
You must be signed in to change notification settings - Fork 0
/
up.ts
27 lines (24 loc) · 842 Bytes
/
up.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Migration, MigrationContext } from './Migration';
import { MigrationStore } from './MigrationStore';
export default async ({
context,
migrations,
migrationStore,
}: {
context?: MigrationContext;
migrations: Migration[];
migrationStore: MigrationStore;
}): Promise<void> => {
if (migrations.length !== new Set(migrations.map((migration) => migration.id)).size) {
throw new Error('duplicate migration id');
}
const appliedMigrations = await migrationStore.getAppliedMigrations();
const migrationsToApply = migrations.filter(
(migration) =>
appliedMigrations.find((appliedMigration) => appliedMigration.migrationId === migration.id) === undefined,
);
for await (const migration of migrationsToApply) {
await migration.up(context);
await migrationStore.insertMigration(migration);
}
};