Skip to content

feat: add apply-migrations script#232

Open
Artitus wants to merge 2 commits intoe2b-dev:mainfrom
Artitus:feat/add-apply-migrations-script
Open

feat: add apply-migrations script#232
Artitus wants to merge 2 commits intoe2b-dev:mainfrom
Artitus:feat/add-apply-migrations-script

Conversation

@Artitus
Copy link

@Artitus Artitus commented Feb 6, 2026

Summary

  • Adds the missing scripts/apply-migrations.ts that the db:migrations:apply package.json script referenced but never existed
  • The script reads all .sql files from migrations/ in timestamp order and executes them against the database using the postgres package
  • Already-applied migrations are detected (via "already exists" / "duplicate" errors) and skipped gracefully
  • Wires up the missing scripts:apply-migrations entry in package.json

Usage

source .env.local && bun run db:migrations:apply

Test plan

  • Verified against a live Supabase database — migrations 2 and 3 applied successfully, migration 1 was correctly skipped (already applied)

Made with Cursor

The `db:migrations:apply` script in package.json referenced a
`scripts:apply-migrations` entry that didn't exist. This adds the
missing `scripts/apply-migrations.ts` that reads SQL files from
the migrations/ directory and executes them in order against the
database. Already-applied migrations are detected and skipped.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel
Copy link

vercel bot commented Feb 6, 2026

@Artitus is attempting to deploy a commit to the E2B Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

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

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: 17bb553cbf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +31 to +34
if (
err.message.includes('already exists') ||
err.message.includes('duplicate')
) {

Choose a reason for hiding this comment

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

P1 Badge Treating any “duplicate” error as already-applied migration

The script skips a migration whenever the error message contains “already exists” or “duplicate”. That’s broader than “schema already applied”: data migrations can legitimately fail with duplicate key value violates unique constraint when inserting rows, or unique-index creation can fail due to real data conflicts. In those cases the migration has not been applied, but this code will log it as skipped and continue, leaving the DB in a partially migrated state without surfacing the failure. Consider using a dedicated migrations table or only skipping known idempotent DDL errors tied to the specific migration.

Useful? React with 👍 / 👎.

Replace the manual migration instructions with the new
`bun run db:migrations:apply` command, while keeping the
manual approach as an alternative.

Co-authored-by: Cursor <cursoragent@cursor.com>
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