If you often create columns / tables with the same settings or groups of columns, you must create extension methods for your migrations!
For example, almost every of my tables has CreateAt and UpdateAt DateTime columns, so I hacked into a small extension method, so I can say:
Create.Table("Foos"). WithColumn("a"). WithTimestamps();
I think I created the extension method correctly ... I know this works, but FluentMigrator has many interfaces ... here it is:
public static class MigrationExtensions { public static ICreateTableWithColumnSyntax WithTimestamps(this ICreateTableWithColumnSyntax root) { return root. WithColumn("CreatedAt").AsDateTime().NotNullable(). WithColumn("UpdatedAt").AsDateTime().NotNullable(); } }
Similarly, almost every one of my tables has an int primary key called "Id", so I think I'm going to add Table.CreateWithId("Foos") to always add this Id for me. Not sure ... I actually started using FluentMigrator today, but you should always be refactoring whenever possible!
NOTE. . If you are doing helper / extension methods for your migrations, you should never ever change what those methods do. If you do this, someone might try to start your migrations, and everything could explode, because the helper methods that you used to create migration # 1 work differently than before.
Here is the code to create the columns to help you create helper methods: https://github.com/schambers/fluentmigrator/blob/master/src/FluentMigrator/Builders/Create/Column/CreateColumnExpressionBuilder.cs
remi Apr 04 2018-11-11T00: 00Z
source share