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

Update deployment to run migrations as a separate step #1778

Merged

Conversation

habdelra
Copy link
Contributor

@habdelra habdelra commented Nov 8, 2024

This PR adds support to run DB migrations as a separate step. In this PR I introduce a new Docker file that allows the migrations to run completely independent from the realm server (having a separate postgres workspace worked out really nicely).

In this PR I actually make running the migrations automatically a flag that we set on the command line. Keep in mind that we want our tests to use the latest schema (the tests run in their own DBs). This also extends to matrix tests too. I opted to let the local dev version of the app auto migrate as well since that seems to work pretty well for our current dev experience. we can make that an opt-in feature if we want, but I'm guessing that most devs will want auto-migrate. it's one less thing to have to troubleshoot when things break (disabling auto migrate in your dev env is also quite simple). The hosted env's, though, do not auto migrate, and instead rely on the newly introduced migration deployment step for their migrations.

This PR depends on the infra PR https://github.com/cardstack/infra/pull/559 which provides an ECS service for the pg migration script to run in that is independent of the realm server.

As part of this I found a bunch of issues when we separated out the postgres workspace from the realm server in that specifically the migration related scripts in the realm-server workspace didn't work anymore. those actually needed to move over to the postgres workspace. I also had to tweak the drop-all-dbs to work using the new postgres workspace, which i renamed to full-reset to be more clear what it actually does.

TODO:

  • Deploy infra PR to staging
  • Deploy infra PR to production
  • Test deploy in staging

Copy link

github-actions bot commented Nov 8, 2024

Host Test Results

    1 files  ±0      1 suites  ±0   21m 12s ⏱️ +3s
678 tests ±0  677 ✔️ ±0  1 💤 ±0  0 ±0 
683 runs  ±0  682 ✔️ ±0  1 💤 ±0  0 ±0 

Results for commit 3c07142. ± Comparison against base commit 953143e.

♻️ This comment has been updated with latest results.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was so convenient having this script here I decided to just sym link it to its new location

Copy link
Contributor Author

@habdelra habdelra Nov 8, 2024

Choose a reason for hiding this comment

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

this is just a rename--the symlink i made to it confused github

Copy link
Contributor Author

@habdelra habdelra Nov 8, 2024

Choose a reason for hiding this comment

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

this is just a rename--the symlink i made to it confused github

@habdelra habdelra marked this pull request as ready for review November 8, 2024 19:19
@habdelra habdelra requested a review from a team November 8, 2024 19:19
Copy link
Contributor

@backspace backspace left a comment

Choose a reason for hiding this comment

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

Let’s see it in action!

@habdelra
Copy link
Contributor Author

habdelra commented Nov 8, 2024

Let’s see it in action!

infra has been deployed to staging and prod, and I confirmed the new boxel-pg-migrate ECS service is running. feel free to give it a shot. like i said, I'm not too sure that the workflow updates will be picked up outside of the main branch.

@backspace
Copy link
Contributor

I think you’re right about this PR’s workflows not being used in deployment but I’ll try it to confirm.

@backspace
Copy link
Contributor

It’s happening 😆 I’m honestly always unsure

boxel@f788e2b 2024-11-08 13-58-57

@habdelra
Copy link
Contributor Author

habdelra commented Nov 8, 2024

Ah, I see an error in the docker image:

/bin/sh: 1: ./node_modules/.bin/node-pg-migrate: not found

@habdelra
Copy link
Contributor Author

the migration script is now running succesfully in staging:

image

@habdelra habdelra merged commit 7316503 into main Nov 11, 2024
35 checks passed
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.

3 participants