Skip to content

Allow schema specification when migrating#611

Merged
slifty merged 1 commit into
mainfrom
609-switch-migration-library
Nov 17, 2023
Merged

Allow schema specification when migrating#611
slifty merged 1 commit into
mainfrom
609-switch-migration-library

Conversation

@slifty

@slifty slifty commented Nov 17, 2023

Copy link
Copy Markdown
Member

This PR replaces our migration tool with one that supports multiple schemas, and utilizes that tool when running tests.

Resolves #609

The upstream copy of our postgres-migrations project has an issue where
it does not support postgres schemas, and if ANY schema has a migrations
table then migrations will fail.  This was frustrating for running
tests, but recently while looking into developing a job queue which
would require a separate schema it became a blocking issue.

Upstream also appears to no longer be maintained (the most recent commit
as of this writing was about 2 years ago, and the PR we opened to fix
the schema limitation has been open for around 18 months).

Fortunately there is a fork of the library designed specifically for
adding schema support.

This replaces the library with the modified version and also updates our
migration code to utilize the schema functionality.

Issue #609 Consider finding a new tool for migrations
@slifty slifty requested a review from jasonaowen November 17, 2023 14:36
Comment thread src/database/migrate.ts
import { db } from './db';

export const migrate = async (): Promise<void> => {
export const migrate = async (schema = 'public'): Promise<void> => {

@slifty slifty Nov 17, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Someone with stronger DB opinions should let me know if it would be better to use a pdc schema as our default, rather than public.

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.

I think it's OK to default to public. My sense is that more often than not a dedicated database instance gets created for each separate application.

@codecov

codecov Bot commented Nov 17, 2023

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (28396c8) 95.44% compared to head (3395305) 95.44%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #611   +/-   ##
=======================================
  Coverage   95.44%   95.44%           
=======================================
  Files          70       70           
  Lines        1009     1009           
  Branches      163      164    +1     
=======================================
  Hits          963      963           
  Misses         43       43           
  Partials        3        3           

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

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

LGTM. I didn't try it locally, but I see the checks passed and no red flags stand out.

Comment thread package.json
"pino": "^8.16.2",
"pino-http": "^8.5.1",
"postgres-migrations": "^5.3.0",
"postgres-schema-migrations": "^6.1.0",

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.

Nice find! You might want to mention this package in ThomWright/postgres-migrations#93 so others can find it too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I actually learned about it from a comment on the issue that PR addresses (ThomWright/postgres-migrations#92 (comment))

@slifty slifty merged commit a98bd02 into main Nov 17, 2023
@slifty slifty deleted the 609-switch-migration-library branch November 17, 2023 16:39

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

Oh perfect - that fork is on npm after all! I'd missed that it got renamed.

I was able to run this (well, main, since this is a post-hoc review) locally without issue.

+1! Great work, @slifty. 💙

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.

Consider finding a new tool for migrations

3 participants