forked from fluentmigrator/fluentmigrator
-
Notifications
You must be signed in to change notification settings - Fork 1
Enforce migration version numbering rules
Daniel Lee edited this page May 2, 2013
·
4 revisions
Frequently, it is useful for a project to employ a specific system for migration version numbering. A useful technique for simplying and encoding this system is with a custom attribute that inherits from MigrationAttribute
.
An example is below. This uses a system where the migration version is of the format BBYYYYMMDDHHMM, where BB is a branch, YYYY is year, MM is date, and so on.
///
/// Mark all migrations with this INSTEAD of [Migration].
///
public class MyCustomMigrationAttribute : FluentMigrator.MigrationAttribute
{
public MyCustomMigrationAttribute(int branchnumber, int year, int month, int day, int hour, int minute, string author)
: base(CalculateValue(branchnumber, year, month, day, hour, minute))
{
this.Author = author;
}
public string Author { get; private set; }
private static long CalculateValue(int branchnumber, int year, int month, int day, int hour, int minute)
{
return branchnumber* 1000000000000L + year * 100000000L + month * 1000000L + day * 10000L + hour * 100L + minute;
}
}
A migration class that uses this attribute might look like this:
[MyCustomMigration(author: "Scott Stafford", changeRequest: 12, year: 2012, month: 8, day: 7, hour: 14, minute: 01)]
public class TestLcmpMigration : Migration
{
public override void Down() { /* ... */ }
public override void Up() { /* ... */ }
}
- Getting FluentMigrator
- How to create a Migration
- Fluent Interface
- Migration Runners
- Use inbuilt database functions when setting the default value
- Sql Server Specific Extensions
- Raw Sql Helper for inserting data
- Auto Reversing Migrations
- Resharper File Template
- Transaction Modes for the Migration Runner
- ApplicationContext: Passing parameters to Migrations
- Dealing with Multiple Database Types
- Filter migrations run based on Tags
- Enforce migration version numbering rules
- Create custom metadata for the VersionInfo table