Skip to content

fix(db): mechanism for db provisioning/migrations (PXP-7918) #80

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

Merged
merged 2 commits into from
Mar 31, 2021

Conversation

williamhaley
Copy link
Contributor

Jira Ticket: PXP-7918

New Features

  • Meta-migrations mechanism to orchestrate new DBs, users, and other non-application level migrations

Bug Fixes

  • Resolves an issue for existing users who would be adding MDS to their stack

@@ -0,0 +1,33 @@
#!/usr/bin/env bash
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This all feels a bit hokey, but (after some searching) I found there is no mainline way out-of-the-box to set up a simple "run this script at startup" process for postgres' docker image so I created a custom entrypoint/command here to accomplish the task of setting up DBs and doing other DB work to orchestrate data as needed.

set -e

# Initialize the DB, but don't allow outside connections yet.
docker-entrypoint.sh postgres -c listen_addresses='127.0.0.1' &
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This relates to running the script after the init scripts but before the DB is accessible to other apps on the network. That distinction is significant because our apps (mostly) wait for the DB to be available and once it's online they get to work.

# Run migrations/scripts that should run on every start. This is handy for data
# we want to backfill or otherwise migrate for users.
gosu postgres bash -c "(
source /usr/local/bin/docker-entrypoint.sh
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Official maintainers have considered that users like us may want this sort of behavior where we can run migrations or other scripts against Postgres and have done some work that allows us to hook into their entrypoint and create our own for this sort of behavior.

@williamhaley
Copy link
Contributor Author

williamhaley commented Mar 22, 2021

I will happily take in any/all suggestions for other ways to go about this sort of thing and re-think the implementation if this doesn't seem ideal. 🙇 These are some alternatives I was thinking about...

  1. A manual process. Give users explicit instructions for adding new DBs, users, or other migrations we need them to do

    A bit clunky, and requires maintaining documentation

  2. Alembic or similar mechanism to run meta/orchestration migrations

    We'd need our own migration service or custom postgres image, which is just One More Thing to maintain and we'd have to update our apps to wait until the migration service is complete, not just that Postgres is online

@williamhaley williamhaley marked this pull request as ready for review March 22, 2021 18:33
@williamhaley williamhaley changed the title fix(db): mechanism for db provisioning/migrations fix(db): mechanism for db provisioning/migrations (PXP-7918) Mar 22, 2021
@xritter1
Copy link
Contributor

@paulineribeyre

Copy link
Contributor

@paulineribeyre paulineribeyre left a comment

Choose a reason for hiding this comment

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

😄

@williamhaley williamhaley merged commit 3e8284e into master Mar 31, 2021
@williamhaley williamhaley deleted the fix/db branch March 31, 2021 21:15
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