Reputation: 6974
In my app, built with Laravel 5.1, I have a branch dev.
I had to implement 2 new features, so I created first branch (starting from dev) that needed 2 tables (so new migrations), then, when I finished it, I created second branch (starting to dev) and also this feature needed a different table so new migration.
So my situation is something like:
branch 1 -> migration1
branch 2 -> migration2, migration3
But now I need to change (many columns) the table related to branch1 so I should rollback migration, because I would not make new migration for change but I would rollback migration and recreate.
But my problem now is that if I return in my branch1 and try to do:
php artisan:migrate rollback
The latest migrations (on my db) are the tables for branch2 (migration2, migration3) and not the table related to branch1 (migration1).
So what is the right way for manage migration between many branch?
Upvotes: 5
Views: 2064
Reputation: 29019
I would suggest to create a copy of your database table and denote them in your .env
file:
DB_DATABASE_BRANCH=branchtable
DB_DATABASE=mastertable
then switch to your branch and change in config/database.php
your database driver to DB_DATABASE_BRANCH
'database' => env('DB_DATABASE_BRANCH', 'forge'),
Since config/database.php
is tracked by git, you will automatically switch your database when using git checkout ***
. This is better the Odyssee's solution because you do not need to touch your .env
file whenever you switch your branch.
Checkout my blog post for more details.
Upvotes: 0
Reputation: 2463
When I create a new branch in a larger project. For example, when starting a refactor. I create a copy of the database and prefix this copy with the branch name. This saves many headaches when switching back to the current master or production branches for quick bug fixes,... This way you will never have any migration conflicts as you describe in your question.
When switching branches I update my .env
database name and I clear the application's cache. This way Laravel starts using the database corresponding to the state your application/migrations are in.
php artisan config:cache
php artisan config:clear
php artisan cache:clear
Upvotes: 1