Skip to content

Commit 5a255fe

Browse files
committed
fix(db): forward force flags for local and dev schema pushes
1 parent ae54aeb commit 5a255fe

5 files changed

Lines changed: 20 additions & 5 deletions

File tree

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ If you prefer not to use Docker. **All commands run from the repository root unl
254254
cd packages/db && bun run db:migrate && cd ../..
255255
```
256256

257-
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 both local and CI/CD setups.
257+
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 or backfills. For disposable local/dev databases, `bun run db:push --force` accepts Drizzle's data-loss prompts, including column drops.
258258

259259
4. **Run the Development Servers:**
260260

.github/workflows/migrations.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ jobs:
7171
7272
if [ "${ENVIRONMENT}" = "dev" ]; then
7373
echo "Dev environment — pushing schema directly (db:push)"
74+
# Dev deliberately forces direct schema reconciliation; staging and
75+
# production use guarded versioned migrations in the other branch.
7476
# drizzle-kit push needs a TTY to resolve ambiguous renames (--force only
7577
# covers data-loss). In CI it throws "Interactive prompts require a TTY
7678
# terminal" but still exits 0, so the job goes green without applying the

packages/db/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"scripts": {
3030
"db:generate": "bunx drizzle-kit generate --config=./drizzle.config.ts",
31-
"db:push": "bunx drizzle-kit push --config=./drizzle.config.ts && bun --env-file=.env run ./scripts/reconcile-credential-group-resource-policies.ts && bun --env-file=.env run ./scripts/reconcile-oauth-provider.ts && bun --env-file=.env run ./script-migrations/0016_backfill_search_vectors.ts",
31+
"db:push": "bun --env-file=.env run ./scripts/push.ts",
3232
"db:migrate": "bun --env-file=.env run ./scripts/migrate.ts",
3333
"db:reconcile-fork-kb-file-ownership": "bun --env-file=.env run ./scripts/reconcile-fork-kb-file-ownership.ts",
3434
"db:reconcile-workspace-storage": "bun --env-file=.env run ./scripts/reconcile-workspace-storage.ts",

packages/db/script-migrations/0010_backfill_credential_group_resource_policies.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ describe('Credential Group resource policy lifecycle', () => {
358358

359359
expect(migration).toContain('CREATE TABLE "resource_policy"')
360360
expect(migration).not.toContain('credential_group_resource_policy_lifecycle')
361-
expect(packageJson.scripts['db:push']).toContain(
362-
'scripts/reconcile-credential-group-resource-policies.ts'
363-
)
361+
expect(packageJson.scripts['db:push']).toContain('scripts/push.ts')
362+
const pushSource = await readFile(new URL('../scripts/push.ts', import.meta.url), 'utf8')
363+
expect(pushSource).toContain('scripts/reconcile-credential-group-resource-policies.ts')
364364
expect(helperSource).not.toContain('LegacyResourcePolicy')
365365
expect(helperSource).not.toContain("document ? 'grants'")
366366
})

packages/db/scripts/push.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/** Forward push flags to Drizzle before running the schema reconciliation steps. */
2+
const commands = [
3+
['bunx', 'drizzle-kit', 'push', '--config=./drizzle.config.ts', ...process.argv.slice(2)],
4+
['bun', '--env-file=.env', 'run', './scripts/reconcile-credential-group-resource-policies.ts'],
5+
['bun', '--env-file=.env', 'run', './scripts/reconcile-oauth-provider.ts'],
6+
['bun', '--env-file=.env', 'run', './script-migrations/0016_backfill_search_vectors.ts'],
7+
]
8+
9+
for (const command of commands) {
10+
const child = Bun.spawn(command, { stdin: 'inherit', stdout: 'inherit', stderr: 'inherit' })
11+
const exitCode = await child.exited
12+
if (exitCode !== 0) process.exit(exitCode)
13+
}

0 commit comments

Comments
 (0)