MCPcopy
hub / github.com/anomalyco/opencode / check

Function check

packages/core/script/migration.ts:64–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

62}
63
64async function check() {
65 const temporary = await fs.mkdtemp(path.join(os.tmpdir(), "opencode-core-migration-check-"))
66 const incremental = path.join(temporary, "incremental")
67 const full = path.join(temporary, "full")
68 try {
69 await fs.mkdir(incremental)
70 await fs.mkdir(path.join(incremental, "baseline"))
71 await fs.copyFile(snapshot, path.join(incremental, "baseline/snapshot.json"))
72 await drizzle(temporary, incremental)
73 if ((await generatedMigrations(incremental)).length > 0) {
74 throw new Error(
75 "Core schema has ungenerated database migrations. Run `bun script/migration.ts` from packages/core.",
76 )
77 }
78
79 await fs.mkdir(full)
80 await drizzle(temporary, full, "schema")
81 if ((await Bun.file(schema).text()) !== (await formatTypescript(renderSchema(await generatedSql(full))))) {
82 throw new Error("Current database schema is stale. Run `bun script/migration.ts` from packages/core.")
83 }
84
85 const migrations = await typescriptMigrations()
86 if ((await Bun.file(registry).text()) !== (await formatTypescript(renderRegistry(migrations)))) {
87 throw new Error("Database migration registry is stale. Run `bun script/migration.ts` from packages/core.")
88 }
89 } finally {
90 await fs.rm(temporary, { recursive: true, force: true })
91 }
92}
93
94async function drizzle(temporary: string, output: string, name?: string) {
95 const config = path.join(temporary, `${path.basename(output)}.config.ts`)

Callers 2

migration.tsFile · 0.70
waitFunction · 0.50

Calls 9

drizzleFunction · 0.85
generatedMigrationsFunction · 0.85
formatTypescriptFunction · 0.85
renderSchemaFunction · 0.85
generatedSqlFunction · 0.85
typescriptMigrationsFunction · 0.85
renderRegistryFunction · 0.85
fileMethod · 0.80
textMethod · 0.65

Tested by 1

waitFunction · 0.40