image/svg+xml

Added Feature to Fluent Migrator

Migration scripts for Sql Server support creating indexes with "include" columns.

Motivation

When using Fluent Migrator to write migration scripts, I wanted to be able to create indexes in SQL Server with include columns.

Background

When indexes are created for SQL Server that require include columns, there was no method for doing this without writing raw SQL in the migration script. The intended outcome of this work was to allow indexes with include columns to be created in C# using the following syntax:

Create.Index("IX").OnTable("TestTable")
    .OnColumn("Id").Ascending()
    .WithOptions().Include("Name");

This code should also support indexes with multiple include columns:

Create.Index("IX").OnTable("TestTable")
    .OnColumn("Id").Ascending()
    .WithOptions()
    .Include("Name").Include("DOB");

Implementation

To implement this, I did the following:

Evaluation

After this was completed, I had an increased my level of confidence for writing unit tests using the NUnit test framework.

Pull Request Avaliable on Github

The pull request for this work is avaliable, see Pull Request 409: Adds Support For Indexes With Include Columns using SqlServerExtensions

About Project - Fluent Migrator

The fluentmigrator project is owned by Sean Chambers and it enables database migration scripts to be written in C# without requiring schema or data changes to use SQL strings.

Find out more at: https://github.com/schambers/fluentmigrator/