Skip to content

Wire PostgreSQL migrations into deploy hook - #77

Merged
KagamiChan merged 5 commits into
masterfrom
kagami/postgres-deploy-hook
Jul 11, 2026
Merged

KagamiChan merged 5 commits into
masterfrom
kagami/postgres-deploy-hook

Conversation

@KagamiChan

@KagamiChan KagamiChan commented Jul 11, 2026 •

Copy link
Copy Markdown
Member

Summary

  • run the shared db:migrate command from the deploy hook after dependency installation and before pruning or service restart
  • make db:migrate apply Drizzle migrations for PostgreSQL and explicitly no-op for MongoDB
  • abort deployment on migration failure while preserving the existing MongoDB deployment path
  • add timestamped deployment stages, commit IDs, elapsed time, warnings, and failed-stage exit codes without shell tracing
  • sanitize migration failures to exclude stack traces, configured database URLs, and machine-specific paths
  • keep reusable migration error formatting in a side-effect-free module
  • document the deployment-hook lifecycle and PostgreSQL provisioning without exposing machine filesystem paths
  • add regression coverage for backend-aware migrations, hook ordering, safe diagnostics, and error redaction

Validation

  • npm run test:unit
  • npm run type-check
  • npm run lint -- --quiet
  • bash -n github-master-hook
  • MongoDB npm run db:migrate no-op execution

Review

  • CI passes
  • all Copilot review threads are resolved
  • latest Copilot review generated no new comments

Make db:migrate backend-aware so the shared hook preserves MongoDB deployments while applying PostgreSQL migrations before restart. Add stage-based deploy diagnostics, regression coverage, and deployment documentation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 25e0a7c2-d13b-4596-8100-df7bafb6e919

Copilot AI 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.

Pull request overview

This pull request wires the shared db:migrate command into the github-master-hook deploy lifecycle so PostgreSQL migrations run before pruning dependencies and restarting services, while MongoDB deployments explicitly no-op. It also adds structured deploy-stage logging and documents the hook + PostgreSQL provisioning flow.

Changes:

  • Add migrateDatabase() to apply Drizzle migrations for PostgreSQL and no-op for MongoDB, with unit coverage.
  • Update github-master-hook to run npm run db:migrate after npm ci and before npm prune --omit=dev, with stage/timing/commit logging and failure trapping.
  • Document the deploy hook lifecycle and PostgreSQL operational expectations in README + docs.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/hooks.test.ts Adds regression tests asserting hook ordering (migrate before prune/restart) and presence of stage/failure logging without shell tracing.
tests/database-migrations.test.ts Adds unit tests for backend-aware migration behavior (MongoDB no-op, PostgreSQL applies, errors propagate).
src/db/postgres/migrations.ts Introduces migrateDatabase() wrapper to route migrations based on resolved backend.
scripts/postgres-migrate.ts Switches db:migrate entrypoint to call migrateDatabase() and print backend-appropriate completion messaging.
README.md Documents deploy-hook lifecycle, ordering, and log expectations at a high level.
github-master-hook Adds deploy stages, trap-based failure reporting, and runs db:migrate before pruning and restart steps.
docs/postgresql-deployment.md Documents PostgreSQL provisioning/deploy behavior with the updated hook lifecycle and operational checks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/postgres-migrate.ts Resolved
Log only the redacted migration error message so deploy failures do not emit stack traces, filesystem paths, or configured database URLs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 25e0a7c2-d13b-4596-8100-df7bafb6e919

Copilot AI 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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread tests/database-migrations.test.ts Resolved
Move migration error formatting into a side-effect-free module so unit tests do not load dotenv or application configuration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 25e0a7c2-d13b-4596-8100-df7bafb6e919

Copilot AI 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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread scripts/postgres-migrate.ts Resolved
Remove the misleading import guard now that reusable error formatting lives in a side-effect-free module.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 25e0a7c2-d13b-4596-8100-df7bafb6e919

Copilot AI 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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread tests/hooks.test.ts Resolved
Match the repository's Node filesystem import convention in deploy-hook tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 25e0a7c2-d13b-4596-8100-df7bafb6e919

Copilot AI 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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@KagamiChan
KagamiChan merged commit f481740 into master Jul 11, 2026
2 checks passed
@KagamiChan
KagamiChan deleted the kagami/postgres-deploy-hook branch July 11, 2026 18:51
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