ConditionalMigrations

Topics: EF Runtime
Dec 24, 2013 at 10:52 AM
Hi!

In many scenarios a dev using EF Migrations might need write some conditional migrations.
Here, some use cases:
  • Migration to enable change tracking on sql server but only on RELEASE condition and not for development or testing scenarios.
  • Migration to enable some production features like partitioning, only on RELEASE condition and not for debug,testing..
Really, this is not the "Tagged Migrations feature request" and is more easy because no many paths on migration execution can be produced.


I would be interested in contributing this code if the team agree with this,


Thanks
Unai
Jan 13 at 2:22 PM
up!
Coordinator
Jan 15 at 3:02 AM
Hi Unai,

Nice to hear from you! This sounds like something we would be interested in evaluating for including in the EF in the future. Here a few aspects we would like to consider, and it would be great if you could describe what you think about them in more detail to understand what your idea/proposal is:
  1. What are the actual pros and cons of different levels of granularity on this? E.g. from having just some piece of data/tag passed to a migrations that can be accessed programmatically by the code in the Up/Down methods to having attributes annotating the migrations that filter what gets executed based on different state like build configuration, providers, tags, etc. Can one feature be built on top of the other?
  2. What is the end to end experience? Do you have an example of what code/attributes will appear in the migration and how the user will control what migrations get executed or what gets passed to migrations in a common scenario?
Thanks,
Diego
Jan 19 at 3:58 PM
Hi Diego,

1 - Yes, one feature can be created on top of the other, but I think that "Tag Migrations" is more complex because multiple paths on migrations can be created. I think the first steep is create the infrastructure to enable some conditional migrations and after this evaluate if is posible and how multiple paths can be managed.

2 - End to End Experience: Initially with attributes in DbMigrations to set the condition in each migration

[ConfigurationCondition("DEBUG")]
public class SomeMigration : DbMiration { }

[CodeCondition(typeof(Condition)]
public class SomeMigration : DbMigration {}


What do those look like?