cake-contrib / Cake.EntityFramework

A set of Cake aliases for Entity Framework code first migrations.
https://cakebuild.net/extensions/cake-entityframework
MIT License
5 stars 5 forks source link

Allow Force Flag on Migrations #7

Closed PaigeM89 closed 7 years ago

PaigeM89 commented 7 years ago

I need a way to allow data loss on migrations. This is usually the -force command, but there is no way to allow this in the current structure.

There are a few different options for implementing this - we could go with a fluent-like interface, such as migrator.MigrateTo(version).Force(). We could add an overload, like migrator.MigrateTo(version, true) (true being "allow data loss"). Or make a whole new function, like migrator.MigrateWithDataLoss(version).

There are pros & cons to each, and this isn't a flag we want the user to be passing without careful consideration.

Silvenga commented 7 years ago

The project internally uses the EF migrator - I'm not sure there's an API for forcing database migrations, we'll need to have to look at the code for the EF migrator tool to see how they do it.

Fluent would be nice, maybe on the config side?

PaigeM89 commented 7 years ago

You can configure the migrator itself via the configuration options:

_dbMigrator.Configuration.AutomaticMigrationDataLossAllowed = true;

We'd just need to expose this functionality in a consistent way. By on the config side - do you mean on the EfMigratorSettings object? Or do we want to be able to specify data loss per migrator call?

Silvenga commented 7 years ago

Sweet! Yeah, I was thinking EfMigratorSettings, since that'll basically bind dangerous options to the database connection string.

Silvenga commented 7 years ago

Oh, @PaigeM89 _dbMigrator.Configuration is configured by EfMigratorSettings.ConfigurationClass. I believe force is a different option.