Reputation: 2374
We're using FluentMigrator
in one project. Let's say I got code like this one below.
So every time when we run new migration all the previous data deleting. Is there are way to avoid it and keep safe the data in places which are not changing?
public class Migration1 : Migration
{
public override void Up() {
Create.Table("Project")
.WithColumn("id").AsInt64().PrimaryKey().Identity()
.WithColumn("name").AsString(30).Nullable()
.WithColumn("author").AsString(30).Nullable()
.WithColumn("date").AsDate().Nullable()
.WithColumn("description").AsString(1000).Nullable();
Create.Table("Data")
.WithColumn("id").AsInt64().PrimaryKey().Identity()
.WithColumn("project_id").AsInt64().ForeignKey("Project", "id")
.WithColumn("a").AsInt32().Nullable()
.WithColumn("b").AsInt32().Nullable()
.WithColumn("c").AsInt32().Nullable()
.WithColumn("d").AsInt32().Nullable();
}
public override void Down() {
Delete.Table("data");
Delete.Table("project");
}
}
Upvotes: 0
Views: 127
Reputation: 8983
As part of you Down
method you could create some backup tables which are identical to the table you are deleting but are post fixed with a timestamp. Eg:
Project_201407091059
Data_201407091059
You could then copy all the data from the tables being deleted to these tables.
Upvotes: 1