MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / runCodeMigrations

Function runCodeMigrations

apps/cloud/scripts/code-migrations/runner.ts:84–118  ·  view source on GitHub ↗
(
  sql: CodeMigrationSql,
  migrations: readonly CodeMigration[],
  options: RunCodeMigrationsOptions = {},
)

Source from the content-addressed store, hash-verified

82};
83
84export const runCodeMigrations = async (
85 sql: CodeMigrationSql,
86 migrations: readonly CodeMigration[],
87 options: RunCodeMigrationsOptions = {},
88): Promise<readonly string[]> => {
89 const dryRun = options.dryRun ?? false;
90 const log = options.log ?? console.log;
91 assertUniqueNames(migrations);
92
93 return withMigrationLock(sql, dryRun, async () => {
94 const completed = await readCompletedMigrations(sql, dryRun);
95 const applied: string[] = [];
96
97 for (const migration of migrations) {
98 if (completed.has(migration.name)) {
99 log(`[code-migrate] skip ${migration.name}`);
100 continue;
101 }
102
103 log(`[code-migrate] ${dryRun ? "plan" : "run"} ${migration.name}`);
104 const result = await migration.run({ sql, dryRun, log });
105 log(`[code-migrate] ${result.summary}`);
106
107 if (!dryRun) {
108 await sql.unsafe(
109 `INSERT INTO "${LEDGER_TABLE}" ("name", "time_completed") VALUES ($1, $2)`,
110 [migration.name, Date.now()],
111 );
112 }
113 applied.push(migration.name);
114 }
115
116 return applied;
117 });
118};

Callers 2

migrate.tsFile · 0.85

Calls 6

assertUniqueNamesFunction · 0.85
withMigrationLockFunction · 0.85
readCompletedMigrationsFunction · 0.85
unsafeMethod · 0.80
pushMethod · 0.80
logFunction · 0.50

Tested by

no test coverage detected