()
| 28 | await generate() |
| 29 | |
| 30 | async 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 | |
| 64 | async function check() { |
| 65 | const temporary = await fs.mkdtemp(path.join(os.tmpdir(), "opencode-core-migration-check-")) |
no test coverage detected