drizzle-team / drizzle-team/drizzle-orm

[BUG]: drizzle-kit up leaves the migrations folder half-converted when a journal entry has no snapshot

Open
#6,166 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### What version of `drizzle-kit` are you using?

1.0.0-rc.4

### What version of `drizzle-orm` are you using?

1.0.0-rc.4 (upgrading from `drizzle-orm@0.45.2` / `drizzle-kit@0.31.10`)

### Describe the Bug

`drizzle-kit up` aborts with `No snapshot was found` when any `_journal.json` entry has no corresponding `meta/_snapshot.json`, and it does so **non-atomically and non-resumably**:

- the error names no migration, so there is nothing to act on
- migrations converted before the abort are written to the new folder layout **and their original `.sql` files are deleted**
- the remaining migrations stay in the v0 layout, so the directory is left half-converted
- re-running produces the same error — recovery is `git checkout`, not a retry
- `up` has no flag to skip, list, or repair the offending entries (`--config`, `--dialect`, `--out`, `--output` only)

Journal entries without a snapshot are not exotic. They arise from hand-added SQL files, snapshot-drift repairs, and migrations generated by older versions. In one production repo I looked at, **24 of 138** entries are in this state, and `up` dies at index 3 of 138 — after converting three migrations and deleting their originals.

### Reproduction

```bash
mkdir dk-up-repro && cd dk-up-repro
npm init -y && npm pkg set type=module
npm i -D drizzle-kit@0.31.10 drizzle-orm@0.45.2

cat > schema.ts <<'TS'
import { pgTable, serial, text } from "drizzle-orm/pg-core";
export const users = pgTable("users", { id: serial("id").primaryKey(), name: text("name") });
TS

cat > drizzle.config.ts <<'TS'
import { defineConfig } from "drizzle-kit";
export default defineConfig({
out: "./drizzle", schema: "./schema.ts", dialect: "postgresql",
dbCredentials: { url: "postgres://unused" },
});
TS

npx drizzle-kit generate --name=create_users
npx drizzle-kit generate --custom --name=data_backfill

# Put the project into the state real repos are in: a journal entry whose
# snapshot is absent.
rm drizzle/meta/0001_snapshot.json

npm i -D drizzle-kit@rc drizzle-orm@rc
npx drizzle-kit up
```

### Expected

Either convert the migrations that can be converted and report precisely which entries lack snapshots, or refuse **before writing anything** — so the directory is never left in a mixed state. Ideally name the offending tag(s).

### Actual

```
No snapshot was found
```

exit code 1, and the directory is now half-converted:

```
drizzle/20260822121143_create_users/migration.sql <- converted (original .sql deleted)
drizzle/20260822121143_create_users/snapshot.json
drizzle/0001_data_backfill.sql <- still v0
drizzle/meta/0000_snapshot.json <- stale leftover
drizzle/meta/_journal.json <- still present
```

Re-running `npx drizzle-kit up` prints the same message and does not resume.

### Notes

- #5591 reported the same *message* but a different cause (a beta→beta directory-structure change, with all snapshots present) and is closed. This one is about v0 → v1 with a journal entry that has **no** snapshot.
- The partial-write behaviour is the part that hurts most: on a repo with real history you discover the failure only after some migrations have been rewritten and their originals removed.

Contributor guide

Open the contributing guide

Research direction

Start with the `drizzle-kit up` entry point and reproduce the failure using the commands and missing `drizzle/meta/0001_snapshot.json` described here. Trace how journal entries and snapshots are converted, then verify that missing snapshots are reported by tag and that the command either validates before writing or completes without deleting source migrations, with the reproduction directory left consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, typescript
Domain
cli, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.