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

Containerize db migrations #3435

Closed
humphd opened this issue Apr 8, 2022 · 0 comments · Fixed by #3437
Closed

Containerize db migrations #3435

humphd opened this issue Apr 8, 2022 · 0 comments · Fixed by #3437
Labels
area: docker area: supabase Anything related to Supabase type: enhancement New feature or request
Milestone

Comments

@humphd
Copy link
Contributor

humphd commented Apr 8, 2022

In #3418, @DukeManh is adding automated database migrations via Prisma Migrate. It will allow us to detect when the database schema is out of sync with master, and generate a migration to be applied.

Running this requires network access to the Postgres database, which we have in local development, but not in production (i.e., we don't expose it at all).

Accessing the postgres database requires running our code within the Docker network. This means running the code via a container that runs inside our network. @JerryHue is doing something very similar with postgres backups in #3405.

Unlike the work that @JerryHue is doing, where we can run this automatically and all the time (i.e., we run backups as a cron job), migrations are a one-off action. We won't need them very often. I'd like to be able to run them via Portainer. The process would look like this:

  1. We create a container in src/db that contains all the prisma migrations and code necessary to run them
  2. In CI for staging and production, we build and push images to our registry; however, we don't ever use these images in our docker-compose
  3. When we need to run a migration (e.g., on staging), we ask Portainer to create a new container based on docker.cdot.systems/migrations:staging (or whatever we name it). The same would happen for production (e.g., using:production).

This should mean that the migrations are always in sync with what's needed on the particular environment where we need to run them, since they are built from git on each push/tag.

Our first migrations are needed before 3.0 (see #3433), so we should be able to test this process, document it, and fix any bugs.

@humphd humphd added type: enhancement New feature or request area: docker area: supabase Anything related to Supabase labels Apr 8, 2022
@humphd humphd added this to the 3.0 Release milestone Apr 8, 2022
humphd added a commit to humphd/telescope that referenced this issue Apr 8, 2022
@DukeManh DukeManh linked a pull request Apr 8, 2022 that will close this issue
humphd added a commit that referenced this issue Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: docker area: supabase Anything related to Supabase type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant