-
Notifications
You must be signed in to change notification settings - Fork 108
Add a step to check for migrations and migrate DB if needed #434
base: master
Are you sure you want to change the base?
Conversation
@@ -95,7 +95,10 @@ bundle: | |||
|
|||
setup: build db_create db_migrate | |||
|
|||
publish: build | |||
migrate_if_needed: | |||
bash -c 'if docker-compose run ${RAILS_CONTAINER} rake db:migrate:status | grep "^\s*down"; then docker-compose run ${RAILS_CONTAINER} rake db:migrate; fi' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recently discovered the db:abort_if_pending_migrations
task which pretty much does what it says: exits the rake execution with an error if there are pending migrations.
> rake db:db:abort_if_pending_migrations
You have 10 pending migrations:
20180129223616 AddGroupToTeamMembers
20180204235116 AddMoocToCodeSchools
20180401034441 CreateRoles
20180408172532 AddRoleIdToAdminUser
20180416024105 AddEmailToTeamMember
20180420192231 AddIsPartnerToCodeSchools
20180422030623 CreateSlackUser
20180422031009 DropUserSlackId
20180430161218 AddRepNameToCodeschool
20180711212702 AddMilitarystatusToUser
Run `rails db:migrate` to update your database then try again.
> echo $?
1
And now that I know about it, of course I want to use it! What do you think about this?
migrate_if_needed:
bash -c 'docker-compose run ${RAILS_CONTAINER} rake db:abort_if_pending_migrations || docker-compose run ${RAILS_CONTAINER} rake db:migrate'
migrate_if_needed: | ||
bash -c 'if docker-compose run ${RAILS_CONTAINER} rake db:migrate:status | grep "^\s*down"; then docker-compose run ${RAILS_CONTAINER} rake db:migrate; fi' | ||
|
||
publish: build migrate_if_needed | ||
bin/publish |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 I'm not super familiar with the deployed production environment. Looking at the bin/publish
script has me thinking that this wiring up of a migrate_if_needed
action prior to publish would have the migrations occur in an environment that is not production, but rather in a development or CI environment that is doing Docker image tagging and kubernetes service poking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. I thought maybe the docker container that build was run on would then be promoted to production.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's someone who could walk me through/explain, I would love to write up documentation.
https://github.com/OperationCode/operationcode_backend/wiki/Performing-Production-DB-Migration Here's a wiki article I created now that our former lead has explained our previous steps, you can look for the details but it's as simple as:
|
Description of changes
Adds a step to the deploy process which would run migrations on the docker container before it is published.
Note: The original issue requested a test, but I'm not sure how to write an automated test for something like a Makefile task. I also am not sure how best to test locally, beyond running the new task in isolation (which I have done)
Issue Resolved
Fixes #429