简体   繁体   中英

Is it advisable to enforce that database migrations should have a valid down method and if so how do you do it in your team?

We push a lot of migrations and they tend to go well however I'm aware that there sooner or later we're going push a migration to production that has to be rolled back.

Although we do some basic testing of our code and those tests can be used to prevent pushing we don't have any enforcement that migrations should be reversible (or at least rollbackable).

While I realise that some migrations are not reversible it doesn't change the fact that they may have to be reversed (or at the very least they should make us very aware of the fact that this is a bad-ass migration to get right).

Do you bother enforcing that migrations are reversible and if so how do you do it?

On my project, we write a down migration only when it's straightforward. Sometimes it's impossible to write the reverse direction, eg when we changed the encryption format for passwords.

I would argue that down migrations don't provide that much value if you take appropriate precautions. We deploy to a staging environment, which QA uses to accept features, and deploy to production after the feature's been accepted. If a rollback is truly necessary, we'll use backups.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM