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

Function generate

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

Source from the content-addressed store, hash-verified

28await generate()
29
30async function generate() {
31 const temporary = await fs.mkdtemp(path.join(os.tmpdir(), "opencode-core-migration-"))
32 const incremental = path.join(temporary, "incremental")
33 const full = path.join(temporary, "full")
34 try {
35 await fs.mkdir(incremental)
36 await fs.mkdir(path.join(incremental, "baseline"))
37 await fs.copyFile(snapshot, path.join(incremental, "baseline/snapshot.json"))
38 await drizzle(temporary, incremental, args.values.name)
39
40 const generated = await generatedMigrations(incremental)
41 if (generated.length > 1) throw new Error(`Expected one generated migration, found ${generated.length}.`)
42 const name = generated[0]
43 if (name) {
44 const target = path.join(tsDir, `${name}.ts`)
45 if (await Bun.file(target).exists()) throw new Error(`Database migration already exists: ${name}`)
46 await Bun.write(
47 target,
48 await formatTypescript(
49 renderMigration(name, await Bun.file(path.join(incremental, name, "migration.sql")).text()),
50 ),
51 )
52 await fs.copyFile(path.join(incremental, name, "snapshot.json"), snapshot)
53 }
54
55 await fs.mkdir(full)
56 await drizzle(temporary, full, "schema")
57 await Bun.write(schema, await formatTypescript(renderSchema(await generatedSql(full))))
58 await Bun.write(registry, await formatTypescript(renderRegistry(await typescriptMigrations())))
59 } finally {
60 await fs.rm(temporary, { recursive: true, force: true })
61 }
62}
63
64async function check() {
65 const temporary = await fs.mkdtemp(path.join(os.tmpdir(), "opencode-core-migration-check-"))

Callers 1

migration.tsFile · 0.70

Calls 12

drizzleFunction · 0.85
generatedMigrationsFunction · 0.85
formatTypescriptFunction · 0.85
renderMigrationFunction · 0.85
renderSchemaFunction · 0.85
generatedSqlFunction · 0.85
renderRegistryFunction · 0.85
typescriptMigrationsFunction · 0.85
fileMethod · 0.80
writeMethod · 0.80
textMethod · 0.65
existsMethod · 0.45

Tested by

no test coverage detected