Skip to content

fix(db): make PostgreSQL migrations atomic - #921

Open
onmax wants to merge 1 commit into
nuxt-hub:mainfrom
onmax:fix/postgresql-atomic-migrations
Open

fix(db): make PostgreSQL migrations atomic#921
onmax wants to merge 1 commit into
nuxt-hub:mainfrom
onmax:fix/postgresql-atomic-migrations

Conversation

@onmax

@onmax onmax commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

PostgreSQL migrations are currently executed one statement at a time, with _hub_migrations updated only after every statement succeeds. A later failure can therefore leave committed DDL without a tracker row, while overlapping runners can both decide that the same migration is pending.

Fix

For PostgreSQL only, this PR:

  • takes the same transaction-scoped advisory lock before tracker creation and migration application;
  • rechecks _hub_migrations after acquiring the lock;
  • executes the complete migration and tracker insert in one DO statement, so both succeed or both roll back.

Other dialects keep their existing behavior. Using one server-side statement also avoids requiring interactive transaction support from the driver.

Compatibility

This requires PL/pgSQL, which PostgreSQL installs by default. Commands PostgreSQL forbids inside transactions, such as CREATE INDEX CONCURRENTLY, fail without applying or recording the migration. Neon HTTP was not tested against a live endpoint; Drizzle forwards the wrapper through db.execute() as one query.

@vercel

vercel Bot commented Aug 12, 2026

Copy link
Copy Markdown

@onmax is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new

pkg-pr-new Bot commented Aug 12, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxthub/core@921

commit: c2c59a5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant