image/svg+xml

Added Feature to Fluent Migrator

Migration scripts for Sql Server support creating constraints with 'non-clustered' / 'non-clustered' support.

Motivation

When investigating whether Fluent Migrator was a suitable tool for performing migrations, I identified that it did not support creating constraints that were explicitly clustered on non-clustered.

Background

When a constraint is created on a table in Microsoft SQL Server an index is created on the data. Whether this index is clustered or non-clustered is determined from the rules below (taken from Microsoft TechNet documentation):

This presented a problem for me, as I was dealing with a database where there were tables with non-clustered primary keys and clustered unique constraints. What I wanted to write was:

Create.PrimaryKey("PK")
    .OnTable("TestTable")
    .Column("Id").NonClustered();

Create.UniqueConstraint("UQ")
    .OnTable("TestTable")
    .Column("Name").Clustered();

Implementation

To implement this, I followed the existing pattern in the code base for addngi SQL Server specific extensions. This involved:

To verify my implementation, tests were added:

Evaluation

Pull request went through without any significant issues. I expect this was due to the inclusion of tests and that the code changes made appeared to follow existing architectural patterns in the project.

Pull Request Avaliable on Github

The pull request for this work is avaliable, see Pull Request 301: Adds Constraint Clustering Support For SqlServer

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/