-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: manage database migration #812
feat: manage database migration #812
Conversation
f94c263
to
8ee18f2
Compare
9022b58
to
f1bef92
Compare
@Ubisoft-potato migration pod has IMO, it would be better to run migration before helm upgrades. |
a21ec3c
to
25260b3
Compare
@kentakozuka Currently, the database migration API is implemented in the Batch service, so we can only wait for the Batch service to be deployed and then send the migration request to it.So I am using Let me check if we can make sure Batch service chart could be deployed first when we install or upgrade Bucketeer Helm Charts. |
@Ubisoft-potato, as we spoke, we might achieve our goal of upgrading new schemas without causing downtime by running the migration process outside the Bucketeer app. We could use a script or container deployed temporarily and terminated after upgrading. This guide seems a good solution to our problem. |
@cre8ivejp Let's eliminate migration in the batch service. First, I will create our GitHub workflow for creating migration images using atlasgo. Then, I will add a pre-install helm hook for Bucketeer Charts.
@kentakozuka Please check the new solution here. |
Sounds good to me! |
f4a3257
to
3d74ca9
Compare
83cbfa0
to
1befca2
Compare
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.
@Ubisoft-potato Thanks!
How do we rollback a migration if the migration succeeded but we want to revert it?
Makefile
Outdated
--dir file://migration/mysql \ | ||
--to mysql://${USER}:${PASS}@${HOST}:${PORT}/${DB} \ | ||
--dev-url docker://mysql/8 |
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.
Replace spaces with tabs.
Makefile
Outdated
--dir file://migration/mysql \ | ||
--url mysql://${USER}:${PASS}@${HOST}:${PORT}/${DB} \ |
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.
Replace spaces with tabs.
Makefile
Outdated
.PHONY: install-atlas | ||
install-atlas: | ||
curl -sSf https://atlasgo.sh | sh |
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.
Please add these lines to local-deps
.
@kentakozuka This PR does not include the rollback migration implementation. We will address it in a new PR due to the complexity of the atlas down migration. |
1befca2
to
4628551
Compare
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.
LGTM 🚀
fa65d5f
to
acadfd7
Compare
43fc76a
to
bf7fca3
Compare
Signed-off-by: Alessandro Yuichi Okimoto <[email protected]>
4f9907a
to
09d6fa7
Compare
Signed-off-by: Alessandro Yuichi Okimoto <[email protected]>
09d6fa7
to
7e289b8
Compare
@@ -245,7 +267,7 @@ jobs: | |||
token: ${{ secrets.REPO_ACCESS_PAT }} | |||
workflow: dev-deploy.yaml | |||
ref: master | |||
inputs: '{"ref": "${{ needs.setup.outputs.REF }}", "image_tag": "${{ needs.setup.outputs.IMAGE_TAG }}", "committer": "${{ github.event.head_commit.author.name }}", "commit_message": "${{ needs.setup.outputs.COMMIT_MESSAGE }}", "commit_url": "${{ github.event.head_commit.url }}", "skip_e2e": "${{ github.event.inputs.skip_e2e }}", "skip_sdk_e2e": "${{ github.event.inputs.skip_sdk_e2e }}", "skip_prd_pr": "${{ github.event.inputs.skip_prd_pr }}"}' | |||
inputs: '{"ref": "${{ needs.setup.outputs.REF }}", "image_tag": "${{ needs.setup.outputs.IMAGE_TAG }}", "committer": "${{ github.event.head_commit.author.name }}", "commit_message": "${{ needs.setup.outputs.COMMIT_MESSAGE }}", "commit_url": "${{ github.event.head_commit.url }}", "skip_e2e": "${{ github.event.inputs.skip_e2e }}", "skip_sdk_e2e": "${{ github.event.inputs.skip_sdk_e2e }}", "skip_prd_pr": "${{ github.event.inputs.skip_prd_pr }}", "migration_required": "${{ needs.setup.outputs.MIGRATION_REQUIRED }}"}' |
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.
When deploying, we will need the migration_required
to update the migration container image tag in the dev environment.
@@ -98,13 +106,17 @@ jobs: | |||
IMAGE=`./tools/build/show-image-name.sh $APP` | |||
docker build -f Dockerfile-app-$APP -t bucketeer-$IMAGE:${{ needs.setup.outputs.IMAGE_TAG }} --load . | |||
done | |||
- name: Build and push the Migration image | |||
if: needs.setup.outputs.MIGRATION_REQUIRED == 'true' |
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.
It will only build and push the image when the migration directory changes.
migration: | ||
image: | ||
repository: ghcr.io/bucketeer-io/bucketeer-migration | ||
tag: v0.4.5 # x-release-please-version |
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.
Set the default tag and the comment so the Release Please can update the tag when releasing.
- name: Store the migration_required value to output | ||
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 | ||
id: changes | ||
with: | ||
filters: | | ||
migration: | ||
- 'migration/**' |
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 using the dorny/paths-filter
action, which is great for checking for changes in directories or files.
Signed-off-by: Alessandro Yuichi Okimoto <[email protected]>
0d72467
to
74dc8ad
Compare
Closing this in favor of #1060 |
Fixes #685
Install atlas
We should install atlas first by running this command:
Migration workflow
Create migration file from the dev database. [1]
Explanation: This commmand will create migration files by comparing the migration file directory and dev database. For Example: when the migration directory is empty, after execute this command will creste the migration files that creates all tables.
Check the migration files. [1]
After create migration files, the directory will looks like the following:
Suppose we are currently at version
20240311022556
, so we will check the next migration file, which is version20240311024017
.After executing this command, it will display the migration process for the database.
Merge the PR that contains the migration files. [1]
Triger Github Action to build the migration image. [1]
Helm Hook
As we need to do migration before install or upgrade Bucketeer Helm Charts, so we will add a
pre-install
andpre-upgrade
Helm Hook to do migration process using the migration image that we build. [1] [2]Additionally, we have to set the migration database URL.
Other
If we need to use atlas migrattion in our existing Bucketeer cluster, we need to set the current version for atlas, because atlas will apply migration files from the first to last.
Additionally, atlas will save the migration version in the database table:
atlas_schema_revisions
.For example, suppose our database version is at
20240311022556
, we can use the following command to set the version for atlas:make atlas-set-version VERSION=20240311022556 USER=bucketeer PASS=bucketeer HOST=localhost PORT=3306 DB=bucketeer atlas migrate set 20240311022556 \ --dir file://migration/mysql \ --url mysql://bucketeer:bucketeer@localhost:3306/bucketeer Current version is 20240311022556 (1 set): + 20240311022556 (initialization)
After set atlas version, we wll find
atlas_schema_revisions
table in database.