-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdb-generate.sh
More file actions
executable file
·40 lines (36 loc) · 1.72 KB
/
Copy pathdb-generate.sh
File metadata and controls
executable file
·40 lines (36 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
# db-generate.sh — generate Drizzle migration baselines for both dialects.
#
# Run this script after any schema change. It generates per-dialect migration
# files for SQLite and Postgres and then verifies that the generated output
# has been committed. CI will fail if there is an uncommitted diff in drizzle/.
#
# Usage:
# bun run db:generate # via package.json wrapper
# bash scripts/db-generate.sh # directly
#
# Prerequisites: drizzle.config.sqlite.ts and drizzle.config.postgres.ts must
# both be present and correct. The drizzle-hook.cjs shim remaps .js extension
# imports to .ts so drizzle-kit's bundler can resolve schema files without
# modification.
set -euo pipefail
cd "$(dirname "$0")/.."
echo "[db-generate] Generating SQLite baseline..."
node --require ./scripts/drizzle-hook.cjs ./node_modules/drizzle-kit/bin.cjs generate \
--config drizzle.config.sqlite.ts
echo "[db-generate] Generating Postgres baseline..."
node --require ./scripts/drizzle-hook.cjs ./node_modules/drizzle-kit/bin.cjs generate \
--config drizzle.config.postgres.ts
echo "[db-generate] Checking for uncommitted migration drift..."
# Exit non-zero if either generate produced files that have not been staged.
# This catches the "forgot to commit generated migrations" footgun in CI and
# in pre-commit hooks. Run `git add drizzle/ && git commit` to resolve.
if ! git diff --exit-code drizzle/; then
echo ""
echo "[db-generate] ERROR: drizzle/ contains uncommitted changes after generate."
echo " Stage and commit the generated migration files before pushing:"
echo " git add drizzle/"
echo " git commit -m 'chore: update drizzle migrations'"
exit 1
fi
echo "[db-generate] Done. Both dialects are up to date."