In my project we have a branch model that has a separate development branch and has a separate branch for each release. It may look like this:
dev ______ ______
/ \ / \
master --+---+----+---+---+----+----+--- (...)
r1 \______/ r2 \_______/
So we develop on dev merge it to master and then we create a release branch (r1, r2, ...).
We want to use EF 6 (manual not automatic) migrations but we have a question that we don't know how to answer.
Imagine this:
dev _(1)__ ____(4)
/ \ / \
master --+---+----+---+---+----+-(5)*-+--- (...)
r1 \_(2)__/ r2 \(3)______/
Each number is a migration. They have been added to the source control on each branch AND have been applied to the databases of production instances of our project (we support multiple releases for some time just for fixes) so we cannot downgrade them, they can go only Up(). Asterisk marks the point in time we want to analyze. We want migrations to work this way:
Moreover:
Can that be done? If yes, how?
If you need more details, please ask.
Open the Package Manager Console from Tools → Library Package Manager → Package Manager Console and then run the enable-migrations –EnableAutomaticMigration:$true command (make sure that the default project is the project where your context class is).
To manage migrations, you must first install the EF Core command-line tools. If the DbContext is in a different assembly than the startup project, you can explicitly specify the target and startup projects in either the Package Manager Console tools or the . NET Core CLI tools.
I could try to explain what you can do in each case, but it's quite complex and I would not be able to explain it as well as it's explained here:
Code First Migrations in Team Environments
Although it's complex and you'll have to refer to this document frequently to merge the branches, if you follow this document you'll see that it solves all your questions.
Disclaimer: I know SO should be self contained, but the explanation is so complex and long that I can't even add an abstract here. I hope that the linked MSDN docs don't dissapear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With