Home

Awesome

Build status

Alt.FluentMigrator.VStudio

FluentMigrator is a SQL migration framework designed to help version an application's database. This package allows a developer to create a new migration, update or rollback database within Visual Studio's Package Manager console.

What is Alt.FluentMigrator.VStudio?

Alt.FluentMigrator.VStudio is a set of commands for Package Manager console which makes much easier and faster work with Fluent migrations.

It contains settings file:

and following commands:

How to install?

Please install FluentMigrator first. Required packages: FluentMigrator and FluentMigrator.Console.

Select Default project in Package Manager console and then install Alt.FluentMigrator.VStudio by command:

PM > Install-Package Alt.FluentMigrator.VStudio

Manually create required migrations.json file which contains settings. Please update it.

migrations.json in project

How to configurate migrations.json?

Example:

{
  "ConnectionProjectName": "ConsoleApp",
  "ConnectionName": "TestDb",
  "FluentMigrationToolPath": ".\\packages\\FluentMigrator.Console.3.2.7\\tools\\net461\\x86\\Migrate.exe",
  "DbProvider": "SqlServer",
  "DbProviderHelpUrl": "https://fluentmigrator.github.io/articles/runners/runner-console.html#--provider---dbtype---dbvalue-required",
  "MigrationFolder": "Migrations",
  "ScriptsFolder":  "Scripts",
  "TimeFormat": "yyyyMMddHHmmss"
}
{
	"FluentMigrationToolPath": "%USERPROFILE%\\.nuget\\packages\\fluentmigrator.console\\3.3.2\\net461\\any\\Migrate.exe",
}

Add-FluentMigration

This command generates a new empty migration with a number based on current time with specified time format in migrations.json.

Add-FluentMigration [-MigrationName] <string> [[-AddScript]] [[-ProjectName] <string>]

Parameters

Example

PM > Add-FluentMigration InitialMigration -AddScript

It creates a migration folder if it does not exist. And it creates a script folder because of -AddScript parameter. The migration file will look like this:

using FluentMigrator;

namespace DbMigrations.Migrations
{
	[Migration(20191207222856)]
	public class InitialMigration : Migration
	{
		public override void Up()
		{
			Execute.Script(@"Scripts\20191207222856_InitialMigration.sql");
		}

		public override void Down()
		{
			Execute.Script(@"Scripts\20191207222856_InitialMigration_Down.sql");
		}
	}
}  

Update-FluentDatabase

This command will apply all recently created migrations.

PM > Update-FluentDatabase [[-Script]] [[-Timeout]<int>]

Parameters

If your migration takes a long time and you need to extend it, you can specify -Timeout parameter to 120

PM > Update-FluentDatabase -Timeout 120

Rollback-FluentDatabase

This command will revert all migrations to specified version (migration number).

Parameters

PM > Rollback-FluentDatabase 20191207220215