Skip to content

fix(db): keep migrations, reset, seed and auth schema upgrades from damaging databases - #435

Merged
Brooooooklyn merged 11 commits into
mainfrom
fix/database-safety
Oct 15, 2026
Merged

Brooooooklyn merged 11 commits into
mainfrom
fix/database-safety

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Problem

Some void db commands, the dev migration step, and the auth schema upgrade could change the wrong database, apply SQL that was never checked, or leave a database that no command can repair.

command / step                         what happened on main
─────────────────────────────────────  ─────────────────────────────────────────────────────────────
vp dev, pending DROP without pragma ──▶ warning, then applied anyway (also to DATABASE_URL in .env)
db migrate --remote, D1 binding     ──▶ checks db/migrations, Cloudflare applies ./migrations
  without migrations_dir                (unchecked SQL on production D1)
db rename-migrations, direct CF     ──▶ files renamed, deployed records not → next deploy runs them again
db rename-migrations, MySQL         ──▶ half of the tracking UPDATEs committed, files rolled back
db reset / seed, PostgreSQL enum    ──▶ tables dropped, enum kept → migration fails → empty database
db reset / seed, MySQL view         ──▶ same, with "Table already exists"
db seed --file typo                 ──▶ database reset first, then "file not found"
db reset --remote                   ──▶ flag ignored, local database reset, success printed
db status, PG/MySQL down            ──▶ every migration "pending", exit 0
db export, MySQL                    ──▶ DATE/DATETIME as ISO-Z (restore fails), JSON as [object Object],
                                        tables named _x left out
auth field added to a table w/ rows ──▶ ADD COLUMN NOT NULL fails (SQLite/D1, PG), even with a default
generateId: 'serial' / 'uuid' (PG)  ──▶ generated auth schema has no id default → sign-up fails
first vp dev, D1 + auth             ──▶ "unable to open database file"
PG auth, no DATABASE_URL            ──▶ nothing created, "Applied Better Auth migrations" printed
hosted PG/MySQL, auth step fails    ──▶ 500 with migrations: [] → platform loses the applied files

What this PR changes

destructive SQL ──▶ vp dev applies none of the pending files, prints the validator error, keeps running
                    (same rule as void db migrate and deploy)
remote D1       ──▶ db migrate --remote stops when the binding has no migrations_dir
rename          ──▶ stops for direct Cloudflare (saved, or a real D1/Hyperdrive id in checked-in config)
                    and for an unlinked Void project; MySQL tracking renames run in one transaction
reset / seed    ──▶ PG drops public tables, views, standalone sequences and custom types (public.<name>);
                    stops first if an object in another schema uses one of those views, sequences or types
                    MySQL drops tables and views
                    seed: check file → confirm non-local DB → import module → reset → seed
flags           ──▶ each void db action accepts only the flags it reads
status          ──▶ unreadable local PG/MySQL: `unknown` + warning, or exit 1 when remote is unknown too
export          ──▶ MySQL dates, JSON, BIGINT as MySQL text; only Void's own tables are skipped
auth schema     ──▶ fixed defaults on ADD COLUMN; clear refusal on a populated SQLite/PG table
                    PG serial → identity, uuid → gen_random_uuid(); D1 folder created; PG URL check
handlers        ──▶ 500 body lists the files that committed before the auth step failed
messages        ──▶ paths follow sourceDir; "Start the dev server" (no `void dev` command exists)
codegen / init  ──▶ .void/tsconfig.json lists only files that exist; init demo follows the chosen dialect

Decisions

Topic Decision
Destructive file in dev Refuse every pending file for that start, not only the bad one, so files never apply out of order. The dev server still starts.
rename-migrations on direct Cloudflare Refuse. Renaming is cosmetic: old numeric names and new timestamp names sort the same for Void and for D1. A remote rename needs credentials and an undo across two systems.
Auth fields on MySQL No refusal. MySQL fills old rows on its own, and that path works today. MySQL now gets the declared default.
Auth defaults in the Drizzle schema Not added. .default(false) on user.emailVerified makes drizzle-kit rebuild user on SQLite; on D1 the DROP TABLE user cascades and deletes every session and account.
Unknown void db flags Error. Every flag in help, docs and skills stays accepted.
PG reset and other schemas Before any drop, reset stops and lists the objects in other schemas that use a public view, sequence or type it drops (DROP TYPE … CASCADE would delete their columns). Table drops keep the existing CASCADE behavior.

Behavior changes to note in the release

  • vp dev no longer applies a pending destructive migration without -- void:allow-destructive. It applies no pending file for that start.
  • void db migrate --remote needs migrations_dir on the D1 binding. Void writes it on every provision.
  • void db rename-migrations stops for direct Cloudflare projects and for Void projects that are not linked.
  • void db <action> rejects flags that the action does not use, for example void db reset --remote.
  • void db status exits 1 when it can read neither the local nor the remote PostgreSQL/MySQL database.
  • void db seed asks about a non-local database before it loads the seed module.
  • Adding a required auth field with no fixed default to a SQLite/D1 or PostgreSQL table that has rows fails with a message that says how to fix it.
  • Adding a required unique auth field to a table with two or more rows fails before any change, on every dialect.
  • PostgreSQL apps with generateId: 'serial' or 'uuid': deploy reports schema drift until void db generate writes the migration that adds the id default.

Known limits

  • Direct Cloudflare auth upgrades come from void db generate; a required field with a default still has no backfill there.
  • A fresh clone of a hosted project has no .void/project.json, so rename-migrations cannot see the deployment. After void connect it stops as expected.
  • PostgreSQL reset drops public tables with CASCADE, as before: a view, a foreign key, an inheriting table or a partition in another schema that depends on a public table goes with it.
  • PostgreSQL reset keeps plain functions and schemas other than public. A migration with CREATE FUNCTION or CREATE SCHEMA still fails on reset.
  • A MySQL dump restored with NO_BACKSLASH_ESCAPES changes backslashes in strings (same as main). MySQL export still skips views (same as main).
  • MySQL DDL commits on its own, so a failed MySQL migration can stay partly applied. The error and the docs explain the recovery.

Testing

Check Result
New and changed tests Each fails on main (20 test files, 40 failures on main), for the right reason
PostgreSQL reset postgres:17 and PGlite: enums, domains, ranges, composite types, sequences, views, matviews, extension objects, search_path, objects in other schemas
MySQL reset, export, restore mysql:8.4: views, FKs, dates in a non-UTC zone, JSON, BIGINT limits, DECIMAL, BLOB, BIT, round trip through void db execute --file
Auth migrations node:sqlite, Miniflare D1, postgres:17, mysql:8.4: defaults with quotes and backslashes, refusal, serial and uuid ids with Better Auth sign-up
Dev plugin SQLite, PG, MySQL: harmless start, pragma'd DROP, refused DROP
CLI Built CLI against real databases: every documented flag, menu path, status, seed, rename, absolute paths
vp run build:all, vp run check, vp lint, vp fmt --check pass
vp run test 711 files pass, 1 skipped

🤖 Generated with Claude Code

https://claude.ai/code/session_0123r5HnanmW2VUrZ7VWDufH

…amaging databases

- vp dev applies no pending migration when one is destructive without the pragma
- db migrate --remote stops for a D1 binding without migrations_dir
- db rename-migrations stops for direct Cloudflare and unlinked Void projects;
  MySQL tracking renames run in one transaction
- db reset drops PostgreSQL views, sequences and custom types in public and
  MySQL views; it stops before dropping when another schema uses them
- db seed checks the file and asks about a non-local database before it loads
  the seed module and resets
- void db actions reject flags they do not read
- db status reports an unreadable local database; export keeps MySQL dates,
  JSON and BIGINT as text and keeps app tables that start with _
- auth migrations add fixed defaults and refuse required fields on populated
  SQLite/PostgreSQL tables; PostgreSQL serial and uuid ids get a default
- PostgreSQL and MySQL migrate handlers report committed files when the auth
  step fails
- messages follow sourceDir; init demo follows the chosen database

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0123r5HnanmW2VUrZ7VWDufH
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T10:38:45.609427Z f85f0f2 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://fix-database-safety-void-cloud.voidzero-docs.workers.dev (commit f85f0f2)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://9214c6aa-void-cloud.voidzero-docs.workers.dev f85f0f2 2026-10-15T10:34:40.849Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://4f74974a-void-cloud.voidzero-docs.workers.dev fe59b37 2026-10-15T10:21:34.739Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://b216820c-void-cloud.voidzero-docs.workers.dev ce58ddb 2026-10-15T10:12:59.507Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://7caf537f-void-cloud.voidzero-docs.workers.dev 4f713ce 2026-10-15T09:06:10.413Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://c4182ff3-void-cloud.voidzero-docs.workers.dev d614910 2026-10-15T08:43:02.266Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://efaab3d5-void-cloud.voidzero-docs.workers.dev 8bc5349 2026-10-15T08:25:45.667Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://42cafebd-void-cloud.voidzero-docs.workers.dev 5d1ed44 2026-10-15T08:04:58.935Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://fea03e84-void-cloud.voidzero-docs.workers.dev 99880f3 2026-10-15T07:43:37.890Z Visit the dashboard ↗
  • Build: In progress 🔵

View logs ↗
533f3f0 2026-10-15T07:40:34.455Z View logs ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://0d6f50ae-void-cloud.voidzero-docs.workers.dev 98b9f71 2026-10-15T07:22:45.844Z Visit the dashboard ↗

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 98b9f71914

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/void/src/cli/db.ts
Brooooooklyn and others added 2 commits October 15, 2026 15:40
…s it

Run the other-schema check only when reset drops types or sequences, and
describe what the table drops still remove in other schemas.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0123r5HnanmW2VUrZ7VWDufH
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0123r5HnanmW2VUrZ7VWDufH

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 99880f3439

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/void/src/auth/drizzle.ts
…alls

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0123r5HnanmW2VUrZ7VWDufH

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5d1ed44bd8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/void/src/cli/db.ts Outdated
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0123r5HnanmW2VUrZ7VWDufH

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8bc534927b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/void/src/cli/db.ts
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0123r5HnanmW2VUrZ7VWDufH

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d614910d66

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/void/src/runtime/auth-migrations.ts Outdated
…ry SQL mode

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0123r5HnanmW2VUrZ7VWDufH

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f713ce103

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/void/src/runtime/auth-migrations.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce58ddbb13

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/void/src/auth/node.ts Outdated
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0123r5HnanmW2VUrZ7VWDufH

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fe59b37c6a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/void/src/runtime/auth-migrations.ts Outdated
Comment thread packages/void/src/cli/db.ts
…veral rows

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0123r5HnanmW2VUrZ7VWDufH

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f85f0f26c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/void/src/runtime/auth-migrations.ts
@Brooooooklyn
Brooooooklyn merged commit b89a733 into main Oct 15, 2026
24 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/database-safety branch October 15, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant