I am thinking of using Entity Framework 6
Code First
for database interaction alongside DbUp
for database schema update. The thing is I don't want to use EF
migration for reasons. So, the workflow that I've reached to is:
POCO
s, alter properties, etc) Add-Migration temp_file
in Visual Studio Package Manager Console
Update-Database -Script
in Visual Studio Package Manager Console
sql
scripts including insertion of new row in table __MigrationHistory
.sql
file and past the generated scripts temp_file
It works perfectly locally and on production server, however I don't feel comfortable with adding and then deleting temp_file
every time a new migration is generated (I wish there were a way to permanently stop temp_file
being added to the solution.).
So question: Is there a better way to do database migration with DbUp
using Entity Framework
?
In most of the cases you can skip steps (2) and (6) by utilizing the Automatic Code First Migrations :
Automatic Migrations allows you to use Code First Migrations without having a code file in your project for each change you make .
By default automatic migrations are disabled. You enable them by adding the following like in your db migration configuration class constructor (usually called Configuration
and located under Migrations
sub folder):
AutomaticMigrationsEnabled = true;
Some things to consider:
Maybe this answer is too late, but maybe it will be useful as well. I completely understand your approach to use Entity Framework as ORM and a different tool for schema migration. But choosing DbUp requires you to write manually SQL or generate them as you described above. I suggest considering to use FluentMigrator instead of DbUp. It follows the same philosophy, but allows writing migration steps in C# using fluent syntax. In addition, it supports downgrades, ie rollback.
Here is an example:
[Migration(1)]
public class CreateUserTable : Migration
{
public override void Up()
{
Create.Table("Users");
}
public override void Down()
{
Delete.Table("Users");
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.