4

私は Doctrine 2 に依存する Zend Framework 2 プロジェクトに取り組んでいます。ソースのバージョン管理は GIT によって処理されます。GitFlow を分岐モデルとして使用しています。

問題のある状況:

Migrations on Develop branch:
001.php
002.php
003.php
004.php

Migrations on Production branch:
001.php
002.php

パッチを適用する必要があり、本番ブランチに移行 003.php を作成するとします。また、最終結果が次のようになるように、Develop ブランチへの 003.php の変更を選択する必要があります。

Migrations on Develop branch:
001.php
002.php
*003.php*
003.php
004.php

Migrations on Production branch:
001.php
002.php
*003.php*

しかし、ここに問題があります。開発データベースの現在の移行が 004 で、003 が追加された場合、それは実行されません。

Doctrine 2 の移行を処理する最良の方法は何ですか?

4

2 に答える 2

1

現在のブランチで分岐しているすべての移行を元に戻し、チェックアウトしている新しいブランチに戻すプロセスを自動化するスクリプトを作成しました。

上記のリンクは Symfony 用ですが、ここでは ZF2 用に変更されています (私は ZF2 を使用していないため未テストです)。

doctrine-checkout.sh

#!/bin/bash

# Commit ref of current HEAD
start_commit="$(git rev-parse HEAD)"

# Commit ref of what is to be checked out
dest_commit="$1"

# First common ancestor commit between the two branches
ancestor="$(git merge-base HEAD "$dest_commit")"

# Shorthand for `sudo -u nginx /home/user/project/public/index.php`
# Modify this if you don't run `php public/index.php` as `nginx`
appconsole="sudo -u nginx php $(git rev-parse --show-toplevel)/public/index.php"

# Checkout the ancestor commit to find the first common migration between the
# two branches.  Migrate backwards to this version.
git checkout "$ancestor"
ancestor_migration="$($appconsole migrations:latest)"
git checkout "$start_commit"
$appconsole migrations:migrate "$ancestor_migration"

# Checkout the destination branch and migrate back up

git checkout "$dest_commit"
$appconsole migrations:migrate

これを使用するには、機能ブランチを切り替える必要があるときに、 を実行する代わりに を実行git checkout another-branchしますdoctrine-checkout.sh another-branch

ブランチをリベースして、以前は別のブランチにあった移行を含むコミットを含めると、別のブランチからそのブランチを再度チェックアウトするのが難しくなります。これは、ブランチが追加する移行の背後にあるコミットが、より最近の日付の移行である可能性があるためです。この場合git rebase -i、機能ブランチとedit移行を追加するコミット内で、移行の名前を変更できます。

于 2016-04-27T15:35:35.680 に答える