16
votes

I'm using EF 5.0 and I would like to start using Code-based migrations

I've used fluent migrator and there is a concept of migration order. Migrations can be migrated/rollback no matter the database's migration version.

Does Entity Framework have similar functionality?

I was planning on keeping multiple migration implementations for each database version (likely tied to sprint number at first).

Why do i want this?

Our continuous integration will migrate the database for each environment. It's likely that our Dev build will only be one version "behind" but when we go to QA or PROD environment the database will be behind by multiple migrations.

Maybe i'm going about this the wrong way, in which case I would love to hear opinions on the best way to do migration with CI.

1

1 Answers

19
votes

Yes EF has this functionality.

When you run Add-Migration you'll notice the migration file is prefixed with a timestamp. This is what determines the order, assuming automatic migrations are and always have been disabled.

If you are using a mixture of explicit migrations and automatic migrations then you may notice an additional Source property in the .resx file generated with your migration. This is how EF will determine if it needs to run an automatic migration before it runs your explicit migration.

My experience has taught me these guidelines:

1) Never use automatic migrations.

2) Every developer on your team should ensure they have the latest code before creating a new explicit migration. Sort of obvious, but creating migrations from stale code will result in problems.

3) Developers should make sure that if they write custom SQL in the Up() method of the migration then they write appropriate code (and test it!) to reverse those changes in the Down() method.