Database migrations in a complex branching system

前端 未结 5 809
有刺的猬
有刺的猬 2020-12-04 18:04

In our current development workflow we have introduced database migrations (using Ruckusing) to keep our developers\' db schema\'s in sync. It works great, is pretty straigh

5条回答
  •  不知归路
    2020-12-04 18:55

    An approach I'm thinking of testing in our current project is to create a branch 'migrations' and all (and only) migrations are committed to this branch. Developers must merge from this branch into their current branch before creating a migration so that their migration is always created on top of the latest migration. All projects merge from this branch, so that every branch has a concept of a linear migration history. This gives every branch the ability to move back and forth between database versions. When switching to a branch that depends on a different version of the database, the developer applies whichever migration is appropriate.

    The annoyance (besides the extra work and diligence of committing migrations to the special branch) is remembering which migration corresponds to a particular branch. I guess one way of doing this is instead of committing migrations directly onto the migrations branch, commit the migration (and only the migration) onto the current branch and then cherry pick that commit onto the migrations branch. Then you can just look at the last time the current branch cherry-picked onto the migrations branch and know that that diff contains the necessary migration. I think that would be possible. Also, the developer might create a migration just to see what changes would be necessary, and then try to infer which migration would be appropriate to use.

    Sorry for the vague suggestion; if we do end up trying this approach I'll edit this suggestion with more concrete recommendations.

提交回复
热议问题