cross-branch migration question

I have the following situation. Lets say a project is operated via git feature branches each created from master. So dev1 creates a migration script on branch1 and runs it. The changes are in DB. dev1 moves to branch2 (which is created from master). Since branch1 is not yet merged on master, branch2 has the DB changes from branch1 but not the code that reflects this since branch1 is not yet merged to master. Has anybody dealt with something like automated rollback of branch1 db changes? Any ideas/brainstorming welcome!

Could keep a DB per branch. That would probably solve the issue?

IMO, that is ‘the only way’ because of migration scripts and code.

You mean separate DB per branch? … sounds like a lot of work. I was thinking something with githooks to trigger Yii rollback but cannot think of exact solution

That depends on how you view databases.

I view them as generated output, much like ‘vendor’ directories.

I mean, when developing :)

It sounds like a lot less work, and more robust, than some hacky Git hooks.

OK! You got me interested. Please explain your workflow. I don’t quite get it how to treat databases like vendor folder.

Thanks for your help!

I haven’t settled on a particular workflow with Yii2 yet - but I manage my database purely through migrations, so that - when I switch to a new branch I switch by cloning (new directory) and then generate a new database by running my migrations again, after I’ve run bower and composer install.

So a completely new environment.

I only need to change the name of the database in the local config scripts, and I guess I could automate that, but I don’t.

So nothing fancy.

It also helps ensure that I can reproduce the project at any time. :)

And in that light, my database(s) is merely the output of my migration scripts :)