Skip to content

fix(db): disable statement_timeout for migrations#4714

Open
TheodoreSpeaks wants to merge 2 commits into
stagingfrom
fix/migrate-disable-statement-timeout
Open

fix(db): disable statement_timeout for migrations#4714
TheodoreSpeaks wants to merge 2 commits into
stagingfrom
fix/migrate-disable-statement-timeout

Conversation

@TheodoreSpeaks
Copy link
Copy Markdown
Collaborator

@TheodoreSpeaks TheodoreSpeaks commented May 22, 2026

Summary

  • Set statement_timeout = 0 before running migrations in packages/db/scripts/migrate.ts so long-running DDL isn't killed by the session's statement timeout. Single connection (max: 1), so the SET applies to the whole migration run; no infra/ECS changes needed.
  • Route the Database Migrations CI workflow through the now-guarded migrate.ts (bun run ./scripts/migrate.ts) instead of calling drizzle-kit migrate directly. That path applies migrations to the real dev/staging/prod DBs and previously had no timeout guard. Single source of truth, and it also picks up the richer migration error output.

Type of Change

  • Bug fix

Testing

Tested manually — lint and API boundary validation pass

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

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

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment May 22, 2026 2:36am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 22, 2026

PR Summary

Medium Risk
Changes the GitHub Actions migration runner for live databases, so a mistake could block or misapply migrations. Logic is straightforward but affects production migration execution behavior.

Overview
Updates the Database Migrations GitHub Actions workflow to run migrations via bun run ./scripts/migrate.ts instead of drizzle-kit migrate.

The new migration entrypoint uses a single Postgres connection (max: 1) and explicitly executes SET statement_timeout = 0 before applying Drizzle migrations, reducing the chance of long-running DDL being killed by session timeouts, and adds more detailed error logging on failures.

Reviewed by Cursor Bugbot for commit 1ca4dba. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 22, 2026

Greptile Summary

This PR adds a single SET statement_timeout = 0 statement before running Drizzle migrations so that long-running DDL operations are not killed by the session's default statement timeout. The fix is safe because the pool is constrained to max: 1, ensuring the SET and all subsequent migration queries share the same connection.

  • Disables statement_timeout at the session level before calling migrate(), preventing timeouts on large or slow schema changes.
  • The connection is always closed in the existing finally block via client.end(), so the disabled timeout cannot leak to other parts of the application.

Confidence Score: 5/5

Safe to merge — the change is minimal, well-reasoned, and the disabled timeout cannot escape the migration process.

The single added line correctly targets the session on the only connection in the pool, migration queries inherit the setting, and the connection is always closed in the existing finally block so statement_timeout = 0 is never visible outside this script.

No files require special attention.

Important Files Changed

Filename Overview
packages/db/scripts/migrate.ts Adds SET statement_timeout = 0 before the migrate call; logic is correct given the single-connection pool and the existing client.end() in the finally block.

Sequence Diagram

sequenceDiagram
    participant Script as migrate.ts
    participant Pool as postgres pool (max: 1)
    participant PG as PostgreSQL

    Script->>Pool: "SET statement_timeout = 0"
    Pool->>PG: "SET statement_timeout = 0 (session-level)"
    PG-->>Pool: "OK"
    Pool-->>Script: "OK"

    Script->>Pool: "migrate(drizzle(client), ...)"
    Pool->>PG: "DDL statements (ALTER TABLE, CREATE INDEX ...)"
    PG-->>Pool: "OK (no timeout)"
    Pool-->>Script: "migrations complete"

    Script->>Pool: "client.end()"
    Pool->>PG: "connection closed (timeout setting discarded)"
Loading

Reviews (1): Last reviewed commit: "fix(db): disable statement_timeout for m..." | Re-trigger Greptile

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