mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-24 23:04:55 +00:00
core: load migrations from timestamp-named directories instead of journal
This commit is contained in:
@@ -25,14 +25,28 @@ await Bun.write(
|
|||||||
)
|
)
|
||||||
console.log("Generated models-snapshot.ts")
|
console.log("Generated models-snapshot.ts")
|
||||||
|
|
||||||
// Load migrations from journal
|
// Load migrations from migration directories
|
||||||
const journal = (await Bun.file(path.join(dir, "migration/meta/_journal.json")).json()) as {
|
const migrationDirs = (await fs.promises.readdir(path.join(dir, "migration"), { withFileTypes: true }))
|
||||||
entries: { tag: string; when: number }[]
|
.filter((entry) => entry.isDirectory() && /^\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}/.test(entry.name))
|
||||||
}
|
.map((entry) => entry.name)
|
||||||
|
.sort()
|
||||||
|
|
||||||
const migrations = await Promise.all(
|
const migrations = await Promise.all(
|
||||||
journal.entries.map(async (entry) => {
|
migrationDirs.map(async (name) => {
|
||||||
const sql = await Bun.file(path.join(dir, `migration/${entry.tag}.sql`)).text()
|
const file = path.join(dir, "migration", name, "migration.sql")
|
||||||
return { sql, timestamp: entry.when }
|
const sql = await Bun.file(file).text()
|
||||||
|
const match = /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/.exec(name)
|
||||||
|
const timestamp = match
|
||||||
|
? Date.UTC(
|
||||||
|
Number(match[1]),
|
||||||
|
Number(match[2]) - 1,
|
||||||
|
Number(match[3]),
|
||||||
|
Number(match[4]),
|
||||||
|
Number(match[5]),
|
||||||
|
Number(match[6]),
|
||||||
|
)
|
||||||
|
: 0
|
||||||
|
return { sql, timestamp }
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
console.log(`Loaded ${migrations.length} migrations`)
|
console.log(`Loaded ${migrations.length} migrations`)
|
||||||
|
|||||||
Reference in New Issue
Block a user