Skip to content

Commit 5dc0215

Browse files
committed
Switch to drizzle-kit migrate instead of push
1 parent f7ee214 commit 5dc0215

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

packages/internal/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"typecheck": "tsc --noEmit -p .",
4848
"test": "bun test",
4949
"db:generate": "drizzle-kit generate --config=./src/db/drizzle.config.ts",
50-
"db:migrate": "drizzle-kit push --config=./src/db/drizzle.config.ts",
50+
"db:migrate": "drizzle-kit migrate --config=./src/db/drizzle.config.ts",
5151
"db:start": "docker compose -f ./src/db/docker-compose.yml up --wait && bun run db:generate && (timeout 1 || sleep 1) && bun run db:migrate",
5252
"db:e2e:setup": "bun ./src/db/e2e-setup.ts",
5353
"db:e2e:down": "docker compose -f ./src/db/docker-compose.e2e.yml down --volumes",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-- One-time bootstrap for environments that were previously managed by
2+
-- `drizzle-kit push` and are now switching to `drizzle-kit migrate`.
3+
--
4+
-- `drizzle-kit migrate` skips any migration whose `when` (from
5+
-- meta/_journal.json) is <= the max `created_at` in
6+
-- drizzle.__drizzle_migrations. Inserting a single row whose `created_at`
7+
-- matches the last-already-applied migration's `when` tells drizzle "every
8+
-- migration up to and including this one is already applied", so only new
9+
-- migrations run on the next deploy.
10+
--
11+
-- Run this exactly once per environment (prod, staging, local dev DB that
12+
-- was set up via push). Skip it on a fresh database — `drizzle-kit migrate`
13+
-- will apply all migrations from scratch there.
14+
--
15+
-- 1776719872222 = `when` of 0044_violet_stingray in meta/_journal.json.
16+
-- If you bootstrap a new environment after further migrations have landed,
17+
-- update the value to the latest applied migration's `when`.
18+
19+
CREATE SCHEMA IF NOT EXISTS drizzle;
20+
21+
CREATE TABLE IF NOT EXISTS drizzle.__drizzle_migrations (
22+
id SERIAL PRIMARY KEY,
23+
hash text NOT NULL,
24+
created_at bigint
25+
);
26+
27+
INSERT INTO drizzle.__drizzle_migrations (hash, created_at)
28+
SELECT 'bootstrap-from-push', 1776719872222
29+
WHERE NOT EXISTS (SELECT 1 FROM drizzle.__drizzle_migrations);

0 commit comments

Comments
 (0)