daniellee edited this page Jul 1, 2011 · 4 revisions

FluentMigrator is a database migration framework for .NET written in C#. The basic idea is that you can create migrations which are simply classes that derive from the Migration base class and have a Migration attribute with a unique version number attached to them. Upon executing FluentMigrator, you tell it which version to migrate to and it will run all necessary migrations in order to bring your database up to that version.

Website: https://github.com/schambers/fluentmigrator

How to use the FluentMigratorTask

There are four configuration options that are required to run a migration; the path to the console runner executable, the database provider, the target assembly and a connection string to the database.

An example of a migration to the latest version:

desc "FluentMigrator Test Runner Example"
desc "MigrateDb"
fluentmigrator :migrate do |migrator|
	migrator.command = 'lib/Migrate.exe'
	migrator.provider = 'postgres'
	migrator.target = './Migrations/bin/Release/Migrations.dll'
	migrator.connection = 'Server=;Port=5432;Database=FluentMigrator;User Id=test;Password=test;'
	migrator.verbose = true

Configuration options

command (required)

You must provide the location of the FluentMigrator console runner executable either through the constructor or via the .command setting.

provider (required)

The kind of database you are migrating against. Available choices are: sqlserver2005, sqlserver2008, sqlserverce, sqlserver, mysql, postgres, oracle, sqlite, jet

target (required)

The assembly containing the migrations you want to execute.

connection (required)

The connection string to the server and database you want to execute your migrations against.

task (optional)

The task you want FluentMigrator to perform. Available choices are: migrate:up, migrate (same as migrate:up), migrate:down, rollback, rollback:toversion, rollback:all. Default is ‘migrate’.

verbose (optional)

Show the SQL statements generated and execution time in the console. Default is false.

output (optional)

Output generated SQL to a file. Default is no output (false). Use output_filename to control the filename, otherwise [assemblyname].sql is the default.

output_filename (optional)

The name of the file to output the generated SQL to. The output option must be included for output to be saved to the file.

namespace (optional)

The namespace contains the migrations you want to run. Default is all migrations found within the Target Assembly will be run.

steps (optional)

The number of versions to rollback if the task is ‘rollback’. Default is 1.

preview (optional)

Only output the SQL generated by the migration – do not execute it. Default is false.

version (optional)

The specific version to migrate. Default is 0, which will run all migrations.

profile (optional)

The profile to run after executing migrations.

timeout (optional)

Overrides the default SqlCommand timeout of 30 seconds.

script_directory (optional)

The directory to load SQL scripts specified by migrations from.

show_help (optional)

Displays the console runner’s help menu.

YAML configuration

This task supports configuration via an external YAML file. For more information, see the yamlconfig page.

Command Line Options

This task supports additional command line options, including a .parameters collection for passing in options that are not directly supported. For more information, see the commandline task options documentation.