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

cmd: database migrations should not be run automatically but have a cmd instead #444

Closed
aeneasr opened this issue May 2, 2017 · 7 comments
Labels
feat New feature or request.

Comments

@aeneasr
Copy link
Member

aeneasr commented May 2, 2017

No description provided.

@aeneasr aeneasr added the feat New feature or request. label May 2, 2017
@aeneasr aeneasr modified the milestones: 1.0.0: stable release, 0.8.0: Performance, stability and production-readyness May 2, 2017
@aeneasr
Copy link
Member Author

aeneasr commented May 7, 2017

Resolved in #445

@aeneasr aeneasr closed this as completed May 7, 2017
@meyerzinn
Copy link

meyerzinn commented May 18, 2017

I would actually ask that migrations happen automatically, because as-is it's exceptionally difficult to include hydra in an automated sequence like docker-compose because it requires this extra step.

I think that by passing a database URL to Hydra, you are implicitly authorizing Hydra to do with it what it sees fit. That means it's a blank canvas, ready to be shaped by hydra itself to work. That takes out the human error part, and further allows Hydra to keep its database steady--for example, if there is a small change in an index between migrations and a user doesn't migrate manually, that index remains unfixed regardless of Hydra version. However, if Hydra did SQL migrations automatically, that would not be an issue.

See https://github.com/drone/drone 's use of https://github.com/rubenv/sql-migrate for what I'm talking about.

@aeneasr
Copy link
Member Author

aeneasr commented May 18, 2017

I think that by passing a database URL to Hydra, you are implicitly authorizing Hydra to do with it what it sees fit.

That doesn't include accidental loss of data because a database migration didn't do what it should do. Also:

Dockerfile

FROM oryd/hydra

ENTRYPOINT /go/bin/hydra migrate sql $DATABASE_URL; /go/bin/hydra host

EXPOSE 4444

Hydra is not responsible for your infrastructure set up, all of the infrastructure tools allow automation of this kind.

@meyerzinn
Copy link

Well, to make Hydra production ready it should have integration tests, which would fail fast if data is accidentally lost. The point is basically to couple a Hydra version with a specific migration to allow for a linear progression over time. It makes it more predictable to have Hydra set up the database exactly how it needs.

Just my two cents, but it wouldn't take much to add it.

@meyerzinn
Copy link

Also, this isn't mutually exclusive with a separate migration tool, rather it's complementary. So if you want to upgrade Hydra you could use the manual tool to test it to make sure it didn't somehow get through integration testing with a database bug.

@aeneasr
Copy link
Member Author

aeneasr commented May 18, 2017

Well, to make Hydra production ready it should have integration tests, which would fail fast if data is accidentally lost.

Absolutely, this being done in parts already. The migrations are executed linearly already, and up- as well as down- commands are implemented. It is noteworthy that downwards migrations might cause loss of data as they might (not the case at the moment) remove columns or even tables.

In general, perfect migrations for all environments and databases in the wild are very hard. Sometimes, operators make small fixes to the schema in order to get better performance from the database. Until now, they had no possibility to run migrations manually. This is now the case.

In general, it is the responsibility of operations to properly execute software upgrades (e.g. with release canaries), and separating migration from the actual server is only benefitial here. In fact, I was approached by operations and they asked me specifically to disable auto-migrations and provide a separate command for it, with good reasons for it.

In any case, you are not loosing the ability to execute migrations and run the server in one thing, as I pointed out with the docker example above. You need to be aware of the implications though, which is also why those two commands are now separate.

@aeneasr
Copy link
Member Author

aeneasr commented May 18, 2017

By the way, the ladon migration (the only real thing that changed large portions of the schema) is fully tested - it still needs to be run manually in order to make 100% sure that you don't loose any data due to some weird quirk, as timeouts for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request.
Projects
None yet
Development

No branches or pull requests

2 participants