You can create your own implementation of IDatabaseInitializer
.
Example implementation of an initializer, that will migrate the database to 0 and then migrate all the way to the newest migration (usefull e.g. when running integration tests). In order to do that you would need a DbMigrationsConfiguration
type too.
public class RecreateFromScratch<TContext, TMigrationsConfiguration> :
IDatabaseInitializer<TContext>
where TContext : DbContext
where TMigrationsConfiguration : DbMigrationsConfiguration<TContext>, new()
{
private readonly DbMigrationsConfiguration<TContext> _configuration;
public RecreateFromScratch()
{
_configuration = new TMigrationsConfiguration();
}
public void InitializeDatabase(TContext context)
{
var migrator = new DbMigrator(_configuration);
migrator.Update("0");
migrator.Update();
}
}