Skip to content

Automate db:migrate on merge#11

Merged
andrelandgraf merged 1 commit into
mainfrom
cursor/automate-db-migrate-on-merge-adbb
Sep 18, 2025
Merged

Automate db:migrate on merge#11
andrelandgraf merged 1 commit into
mainfrom
cursor/automate-db-migrate-on-merge-adbb

Conversation

@andrelandgraf

@andrelandgraf andrelandgraf commented Sep 17, 2025

Copy link
Copy Markdown
Contributor

Add a GitHub Actions workflow to automatically run Drizzle migrations on main when schema or migration files are updated.


Open in Cursor Open in Web

Summary by CodeRabbit

  • Chores
    • Introduced an automated CI workflow to apply database migrations after relevant changes are merged into the main branch. This keeps the database schema in sync with code changes, reduces manual steps, and improves deployment reliability. The workflow runs in a controlled environment using secure connection settings, installs necessary dependencies, and executes migrations. No user-facing changes or behavior adjustments are included in this release.

Co-authored-by: andre.timo.landgraf <andre.timo.landgraf@gmail.com>
@cursor

cursor Bot commented Sep 17, 2025

Copy link
Copy Markdown

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@vercel

vercel Bot commented Sep 17, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
allthingsweb Ready Ready Preview Comment Sep 17, 2025 11:51pm

@coderabbitai

coderabbitai Bot commented Sep 17, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a new GitHub Actions workflow to run Drizzle migrations on pushes to main when schema or migration files change, setting DATABASE_URL from secrets, installing dependencies with Bun, and executing bun run db:migrate in the app directory.

Changes

Cohort / File(s) Summary
CI/CD Workflow
.github/workflows/db-migrate.yml
New workflow triggered on push to main when app/src/lib/schema.ts or app/migrations/** change; runs on ubuntu-latest, sets DATABASE_URL from secrets, checks out repo, sets up Bun, installs deps in app/, and runs bun run db:migrate.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Dev as Developer
    participant GH as GitHub
    participant WF as Actions Runner (ubuntu-latest)
    rect rgb(245,245,255)
    Dev->>GH: Push to main
    GH-->>GH: Path filter (schema.ts or migrations/**)
    GH-->>WF: Trigger "Run Drizzle migrations" workflow
    end
    rect rgb(240,255,240)
    WF->>WF: Checkout repository
    WF->>WF: Setup Bun (latest)
    WF->>WF: bun install (working-dir: app/)
    note right of WF: Env: DATABASE_URL from secrets
    WF->>WF: bun run db:migrate (working-dir: app/)
    end
    WF-->>GH: Job status (success/failure)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A push to main, the runners wake,
Bun boots up for schema’s sake.
Drizzle steps through migrations neat,
Secrets whisper DATABASE_URL discreet.
Green checks bloom—CI’s refrain,
Schema changed, ship again.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Automate db:migrate on merge" concisely captures the primary intent of the changeset — adding a GitHub Actions workflow to run database migrations automatically when schema or migration files are updated on main. It is relevant and clear enough for a teammate scanning history, though "on merge" slightly simplifies the trigger because the workflow runs on pushes to main when those files change (which includes merges).
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cursor/automate-db-migrate-on-merge-adbb

Comment @coderabbitai help to get the list of available commands and usage tips.

@cursor cursor 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.

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.


- name: Run migrations
working-directory: app
run: bun run db:migrate

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Database Migration Workflow Vulnerabilities

The db-migrate.yml workflow has two issues. It lacks concurrency control, risking simultaneous database migrations and potential corruption. Additionally, using bun-version: latest creates non-deterministic builds, which could lead to unexpected migration failures from breaking changes in new Bun versions.

Fix in Cursor Fix in Web

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
.github/workflows/db-migrate.yml (3)

21-23: Pin Bun version for reproducible builds.

Using latest can cause inconsistent behavior across deployments. Consider pinning to a specific version.

-        with:
-          bun-version: latest
+        with:
+          bun-version: "1.1.29"

29-31: Add error handling and migration status verification.

Consider adding steps to verify migration success and handle potential failures gracefully.

       - name: Run migrations
         working-directory: app
-        run: bun run db:migrate
+        run: |
+          echo "Running database migrations..."
+          bun run db:migrate
+          echo "Migrations completed successfully"

Additionally, consider adding a step to verify the database connection before running migrations:

      - name: Verify database connection
        working-directory: app
        run: bun run db:check || echo "Database connection check failed"

1-32: Consider adding notification on migration failures.

For production database migrations, consider adding Slack/email notifications on failure to ensure quick response to issues.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c23353b and be1e5bf.

📒 Files selected for processing (1)
  • .github/workflows/db-migrate.yml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Cursor Bugbot
🔇 Additional comments (2)
.github/workflows/db-migrate.yml (2)

7-9: Path filters look correct for DB changes.

The workflow properly triggers on schema file and migration directory changes. This ensures migrations run only when necessary.


14-15: Verify DATABASE_URL secret exists and points to production database.

gh CLI returned HTTP 403 (Resource not accessible by integration) when listing secrets — verification failed. Confirm repository secret DATABASE_URL exists and targets the production DB used by main-branch deployments.

Location: .github/workflows/db-migrate.yml (env: DATABASE_URL, lines 14–15)

@andrelandgraf
andrelandgraf merged commit d607a80 into main Sep 18, 2025
4 of 5 checks passed
@andrelandgraf
andrelandgraf deleted the cursor/automate-db-migrate-on-merge-adbb branch September 18, 2025 00:02
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.

2 participants