This commit is contained in:
Dax Raad
2026-01-14 21:07:36 -05:00
parent af5e405391
commit 7bc8851fc4
34 changed files with 1360 additions and 403 deletions
+6
View File
@@ -99,6 +99,12 @@ const targets = singleFlag
})
: allTargets
// Check migrations are up to date and generate embedded migrations file
console.log("Checking migrations...")
await $`bun run script/check-migrations.ts`
console.log("Generating migrations embed...")
await $`bun run script/generate-migrations.ts`
await $`rm -rf dist`
const binaries: Record<string, string> = {}
@@ -0,0 +1,16 @@
#!/usr/bin/env bun
import { $ } from "bun"
// drizzle-kit check compares schema to migrations, exits non-zero if drift
const result = await $`bun drizzle-kit check`.quiet().nothrow()
if (result.exitCode !== 0) {
console.error("Schema has changes not captured in migrations!")
console.error("Run: bun drizzle-kit generate")
console.error("")
console.error(result.stderr.toString())
process.exit(1)
}
console.log("Migrations are up to date")
@@ -0,0 +1,49 @@
#!/usr/bin/env bun
import { Glob } from "bun"
import path from "path"
import fs from "fs"
const migrationsDir = "./drizzle"
const outFile = "./src/storage/migrations.generated.ts"
if (!fs.existsSync(migrationsDir)) {
console.log("No migrations directory found, creating empty migrations file")
await Bun.write(
outFile,
`// Auto-generated - do not edit
export const migrations: { name: string; sql: string }[] = []
`,
)
process.exit(0)
}
const files = Array.from(new Glob("*.sql").scanSync({ cwd: migrationsDir })).sort()
if (files.length === 0) {
console.log("No migrations found, creating empty migrations file")
await Bun.write(
outFile,
`// Auto-generated - do not edit
export const migrations: { name: string; sql: string }[] = []
`,
)
process.exit(0)
}
const imports = files.map((f, i) => `import m${i} from "../../drizzle/${f}" with { type: "text" }`).join("\n")
const entries = files.map((f, i) => ` { name: "${path.basename(f, ".sql")}", sql: m${i} },`).join("\n")
await Bun.write(
outFile,
`// Auto-generated - do not edit
${imports}
export const migrations = [
${entries}
]
`,
)
console.log(`Generated migrations file with ${files.length} migrations`)