MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / getMissingMigrations

Function getMissingMigrations

migrate-db.ts:29–64  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27}
28
29async function getMissingMigrations(): Promise<string[]> {
30 const existingMigrations: Set<string> = new Set();
31
32 for await (const migrationFile of migrationsDirectory) {
33 // Skip non-files
34 if (!migrationFile.isFile) {
35 continue;
36 }
37
38 // Skip files not in the "001-blah.pgsql" format
39 if (!migrationFile.name.match(/^\d+-.*(\.pgsql)$/)) {
40 continue;
41 }
42
43 existingMigrations.add(migrationFile.name);
44 }
45
46 // Sort migrations
47 const sortedExistingMigrations = [...existingMigrations].sort();
48
49 // Add everything to run, by default
50 const migrationsToExecute = new Set([...sortedExistingMigrations]);
51
52 try {
53 const executedMigrations = await getExecutedMigrations();
54
55 // Remove any existing migrations that were executed, from the list of migrations to execute
56 for (const executedMigration of executedMigrations) {
57 migrationsToExecute.delete(executedMigration);
58 }
59 } catch (_error) {
60 // The table likely doesn't exist, so run everything.
61 }
62
63 return Array.from(migrationsToExecute).sort();
64}
65
66async function runMigrations(missingMigrations: string[]): Promise<void> {
67 for (const missingMigration of missingMigrations) {

Callers 1

migrate-db.tsFile · 0.85

Calls 3

getExecutedMigrationsFunction · 0.85
addMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected