django migrations - workflow with multiple dev branches

前端 未结 2 1192
感动是毒
感动是毒 2021-01-31 07:23

I\'m curious how other django developers manage multiple code branches (in git for instance) with migrations.

My problem is as follows: - we have multiple feature branch

2条回答
  •  后悔当初
    2021-01-31 08:23

    I don't have a good solution to this, but I feel the pain.

    A post-checkout hook will be too late. If you are on branch A and you check out branch B, and B has fewer migrations than A, the rollback information is only in A and needs to be run before checkout.

    I hit this problem when jumping between several commits trying to locate the origin of a bug. Our database (even in development trim) is huge, so dropping and recreating isn't practical.

    I'm imagining a wrapper for git-checkout that:

    1. Notes the newest migration for each of your INSTALLED_APPS
    2. Looks in the requested branch and notes the newest migrations there
    3. For each app where the migrations in #1 are farther ahead than in #2, migrate back to the highest migration in #2
    4. Check out the new branch
    5. For each app where migrations in #2 were ahead of #1, migrate forward

    A simple matter of programming!

提交回复
热议问题