Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log database migrations #641

Merged
merged 1 commit into from
Dec 1, 2023
Merged

Log database migrations #641

merged 1 commit into from
Dec 1, 2023

Conversation

jasonaowen
Copy link
Contributor

Our database migration manager supports logging progress by passing in a simple logging function. Call it with our logger so that we can see fine-grain migration progress detail.

Inspired by reviewing #630 (where we discussed logging for graphile-worker) and #639 (which introduces a database migration).

Example output:

$ npm run migrate:dev

> @pdc/[email protected] migrate:dev
> ts-node -r dotenv/config src/scripts/migrate.ts | pino-pretty

[2023-11-30T00:08:15.855Z] INFO (378990): Starting migrations...
    source: "src/scripts/migrate.ts"
[2023-11-30T00:08:15.862Z] INFO (378990): Loading migrations from: src/database/migrations
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.863Z] INFO (378990): Found migration files: 0001-create-canonical_fields.sql,0002-create-opportunities.sql,0003-create-applicants.sql,0004-create-application_forms.sql,0005-create-application_form_fields.sql,0006-create-proposals.sql,0007-create-proposal_versions.sql,0008-create-proposal_field_values.sql,0009-alter-proposal_field_values-position.sql,0010-alter-proposal_field_values-value_search.sql,0011-rename-canonical_fields.sql,0012-create-platform_provider_responses.sql,0013-create-bulk_uploads.sql,0014-alter-base_fields-description.sql
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.865Z] INFO (378990): Acquiring advisory lock...
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.866Z] INFO (378990): ... acquired advisory lock
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.866Z] INFO (378990): Starting migrations
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.868Z] INFO (378990): Migrations table with name 'public.migrations' exists, filtering not applied migrations.
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.870Z] INFO (378990): Starting migration: 14 alter-base_fields-description
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.870Z] INFO (378990): Running migration in transaction: true
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.879Z] INFO (378990): Ran migration 0014-alter-base_fields-description.sql
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.879Z] INFO (378990): Saving migration to 'public.migrations': 14 | alter-base_fields-description | bb14a65dd01bb6fd3132e2125d4c838bc94be3af
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.880Z] INFO (378990): inserted migration in migrations tablepublic.migrations
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.880Z] INFO (378990): Finished migration: 14 alter-base_fields-description
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.880Z] INFO (378990): Successfully applied migrations: alter-base_fields-description
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.880Z] INFO (378990): Finished migrations
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.880Z] INFO (378990): Releasing advisory lock...
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.882Z] INFO (378990): ... released advisory lock
    source: "src/database/migrate.ts"
[2023-11-30T00:08:15.883Z] INFO (378990): Migrations complete.
    source: "src/scripts/migrate.ts"

Copy link

codecov bot commented Nov 30, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e760c50) 0.00% compared to head (80bd363) 92.93%.

Additional details and impacted files
@@            Coverage Diff            @@
##           main     #641       +/-   ##
=========================================
+ Coverage      0   92.93%   +92.93%     
=========================================
  Files         0       81       +81     
  Lines         0     1133     +1133     
  Branches      0      180      +180     
=========================================
+ Hits          0     1053     +1053     
- Misses        0       75       +75     
- Partials      0        5        +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@slifty slifty left a comment

Choose a reason for hiding this comment

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

😙🤌

(this is meant to be a chef kiss emoji)

Our database migration manager supports logging progress by passing in a
simple logging function. Call it with our logger so that we can see
fine-grain migration progress detail.
@jasonaowen
Copy link
Contributor Author

Rebased to resolve merge conflict with #630 (we both added an import to src/database/migrate.ts). Will merge once CI completes.

@jasonaowen jasonaowen merged commit 9a09212 into main Dec 1, 2023
4 checks passed
@jasonaowen jasonaowen deleted the log-migrations branch December 1, 2023 01:41
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