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

Database migrations for database schema #10

Merged
merged 2 commits into from
Nov 1, 2016

Conversation

syamantm
Copy link

@syamantm syamantm commented Oct 30, 2016

A proposed solution for #9

Implemented automated database migration using sql-migrate and go-bindata, so that the database migrations can be packaged in the same binary. Also added a new command option to
apply the migration changes from command line.

This effectively makes https://github.com/Netflix/chaosmonkey/tree/master/mysql_schema redundant, but I din't want to delete it given that it is still referred in the wiki and therefore is a breaking change.

Happy to open another PR to delete https://github.com/Netflix/chaosmonkey/tree/master/mysql_schema once the new approach is reflected in the wiki(which I can't do unfortunately).

Note: Command to generate migrations.go is go-bindata -pkg migration -o migration/migrations.go migration/mysql. This command should added in the script to build the binary(if there is one?), and possibly before running the tests, but I'm not sure what travis's policy is on uncommitted files.

decided to use rubenv/sql-migrate as this is the only library I could find which is active enough and supports embedding of migrations, which is useful to distribute a single binary. Having said that, this PR is really a proposal, happy to consider other libraries, approaches etc.

Problem

Database setup was a manual process, requiring someone to apply the schema changes manually.

Solution

Implement automated database migration using rubenv/sql-migrate and go-bindata, so that the
database migrations can be packaged in the same binary. Also added a new command option to
apply the migration changes from command line.

Result

Database schema changes can be applied automatically.
"
@@ -18,7 +18,7 @@ install:
#
script:
- diff -u <(echo -n) <(gofmt -d `find . -name '*.go' | grep -v /vendor/`)
- go list ./... | grep -v /vendor/ | xargs -L1 golint
- go list ./... | grep -Ev '/vendor/|/migration' | xargs -L1 golint
Copy link
Author

Choose a reason for hiding this comment

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

/migration contains the generated file from go-bindata which doesn't adhere to linting rules

@lorin lorin self-assigned this Oct 31, 2016
@lorin lorin merged commit 7b6052f into Netflix:master Nov 1, 2016
@lorin
Copy link
Contributor

lorin commented Nov 1, 2016

Thanks for the contribution! I have updated the wiki with info on how to use the new migrate command.

@lorin
Copy link
Contributor

lorin commented Nov 2, 2016

Fixes #9

@syamantm syamantm deleted the issue-9-db-migration branch November 2, 2016 06:39
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.

None yet

2 participants