Skip to content

Instantly share code, notes, and snippets.

@joaofx
Last active March 30, 2017 12:58
Show Gist options
  • Save joaofx/aa4586606568be9790a372c523f25a6a to your computer and use it in GitHub Desktop.
Save joaofx/aa4586606568be9790a372c523f25a6a to your computer and use it in GitHub Desktop.
Migration Conventions
[Migration(201501011618)]
public class CreateProduct : AutoReversingMigration
{
public override void Up()
{
Create.Table("Product")
.WithPrimaryKey() // .WithColumn(p => p.Id).AsInt64().NotNullable().PrimaryKey().Identity()
.WithName() // .WithColumn("Name").AsString(64).NotNullable()
.WithMoney("Price") // .WithColumn("Price").AsDecimal().NotNullable()
}
}

Migration Conventions Ideas

Some constraints:

  • As migrations reflect the database in a certain period of time, C# Expressions can't be used as in case of a class be renamed, old migrations will be changed.
public class MigrationConventions : MigrationConventions
{
public MigrationConventions()
{
// TODO: Convention for versions higher then x
ForPrimaryKey(x => x.WithColumn("Id").AsInt64().NotNullable().PrimaryKey().Identity());
ForName(x => x.WithColumn("Name").AsString(64).NotNullable());
// before version 201501011618 were not nullable
ForMoney(x => x.WithColumn("Price").AsDecimal().NotNullable())
.Before(201501011618, x.WithColumn("Price").AsDecimal());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment