Skip to content

Commit e28acbe

Browse files
committed
refactor(db): generalize push rename handling
1 parent 48e542c commit e28acbe

13 files changed

Lines changed: 476 additions & 283 deletions

‎.github/CONTRIBUTING.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ If you prefer not to use Docker. **All commands run from the repository root unl
256256

257257
For ad-hoc schema iteration during development you can also use `bun run db:push` from `packages/db`, but `db:migrate` is the canonical command for staging and production. `db:push` reconciles directly to the current schema without running versioned migration guards. For disposable local/dev databases, `bun run db:push --force` accepts Drizzle's data-loss prompts, including column drops.
258258

259+
`db:push` treats added and removed columns, tables, and other schema objects as separate creations and deletions. It never infers a rename. For an intentional rename during local development, run `bun run db:push --interactive-renames` in a terminal and select the old object in Drizzle's chooser. This flag does not approve data loss; `--force` controls that separately. Staging and production changes still use reviewed versioned migrations with expand/contract deployment steps.
260+
259261
4. **Run the Development Servers:**
260262

261263
```bash

‎.github/workflows/migrations.yml‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,10 @@ jobs:
7272
fi
7373
7474
if [ "${ENVIRONMENT}" = "dev" ]; then
75-
SIM_DEV_DB_PUSH=1 bun run ./scripts/prepare-dev-schema.ts
7675
echo "Dev environment — pushing schema directly (db:push)"
7776
# Dev deliberately forces direct schema reconciliation; staging and
7877
# production use guarded versioned migrations in the other branch.
79-
# drizzle-kit push needs a TTY to resolve ambiguous renames (--force only
80-
# covers data-loss). In CI it throws "Interactive prompts require a TTY
81-
# terminal" but still exits 0, so the job goes green without applying the
82-
# change. tee keeps the output live in the log; we then fail on drizzle's
83-
# own TTY error. pipefail also preserves a non-zero db:push exit through tee.
84-
SIM_DEV_DB_PUSH=1 bun run db:push --force < /dev/null 2>&1 | tee /tmp/db-push.log
85-
if grep -q "Interactive prompts require a TTY terminal" /tmp/db-push.log; then
86-
echo "ERROR: db:push needs an interactive rename decision; land it as a versioned migration instead of relying on push." >&2
87-
exit 1
88-
fi
78+
SIM_DEV_DB_PUSH=1 bun run db:push --force < /dev/null
8979
else
9080
echo "Applying versioned migrations (db:migrate)"
9181
bun run ./scripts/migrate.ts

‎bun.lock‎

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
],
193193
"patchedDependencies": {
194194
"@better-auth/oauth-provider@1.6.27": "patches/@better-auth%2Foauth-provider@1.6.27.patch",
195+
"drizzle-kit@0.31.10": "patches/drizzle-kit@0.31.10.patch",
195196
"postgres@3.4.9": "patches/postgres@3.4.9.patch"
196197
}
197198
}

‎packages/db/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@
4848
},
4949
"devDependencies": {
5050
"@sim/tsconfig": "workspace:*",
51-
"drizzle-kit": "^0.31.4",
51+
"@types/bun": "1.4.1",
5252
"@types/node": "24.2.1",
53+
"drizzle-kit": "0.31.10",
5354
"typescript": "^7.0.2",
5455
"vitest": "^4.1.0"
5556
}

‎packages/db/scripts/prepare-dev-schema.postgres.test.ts‎

Lines changed: 0 additions & 155 deletions
This file was deleted.

‎packages/db/scripts/prepare-dev-schema.ts‎

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)