I have inherited a project that uses FluentMigrator to manage migrations. Originally the project was executing the migrations in-process when the application started up but I.T. has cracked down on that and we now have to provide scripts to a DBA for all of our database changes.
As part of this transition I have moved the migrations to a new project called Migrations. When I try to execute the migrations using the command line tool it seems to work but no migrations are applied to the database. The database string is correct because if the VersionInfo table does not exist it is created.
There are a number of migrations but most of them are very simple. Here is an example of the first one:
I'm using SQL Server 2012 and FluentMigrator 1.2.1.
Here is the command line in text for gunr2171:
.\Packages\FluentMigrator.1.2.1.0\tools\migrate.exe -c "Data Source=.;Integrated Security=True;Initial Catalog=portal_test" -db sqlserver2012 -a .\source\Migrations\bin\Debug\migrations.dll
And the sample migration:
using System;
using System.Collections.Generic;
using System.Linq;
using FluentMigrator;
namespace Migrations
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores")]
[Migration(1)]
public class M001_CreateAccountTable : Migration
{
public override void Up()
{
Create.Table("Accounts")
.WithColumn("Id").AsInt32().NotNullable().Identity().Unique()
.WithColumn("PartnerCode").AsString().Nullable()
.WithColumn("AccountType").AsInt32().NotNullable()
.WithColumn("Code").AsString().NotNullable().Unique().PrimaryKey()
.WithColumn("Name").AsString().NotNullable()
.WithColumn("PrimaryDomainName").AsString().Nullable()
.WithColumn("IsFederated").AsBoolean().NotNullable()
.WithColumn("IsActive").AsBoolean().Nullable().WithDefaultValue(1)
.WithColumn("FederatedEndpoint").AsString().Nullable()
.WithColumn("CreatedBy").AsString().NotNullable()
.WithColumn("CreatedOn").AsDateTime().NotNullable().WithDefaultValue(DateTime.Now)
.WithColumn("ModifiedBy").AsString().NotNullable()
.WithColumn("ModifiedOn").AsDateTime().NotNullable().WithDefaultValue(DateTime.Now);
}
public override void Down()
{
Delete.Table("Accounts");
}
}
}
I was getting the same thing, and it turned out to be that the assembly with the migrations in it had been written using version, let's say, 1.x, and I was running them with the Migrate.exe from version 2.x.
Using the Migrate.exe with the same version that was used to build the migrations DLL solved it for me.
I had a similar issue where I was running the migrate.exe
from a command prompt to test my first migration to see how it worked.
I found my issue was that I had added Migrator Tags
as documented here to the top of the InitialMigration
class
[Tags("Localhost","Development","Test","Production")] // Added these
public class InitialMigration : Migration
{
// Migration here
}
When I ran the command from a command prompt I missed out the --tag
parameter in the command so this command:
migrate.exe --conn="Server=.;Database=my_db;Trusted_Connection=True;Encrypt=True;Connection Timeout=30;" --provider=SqlServer --assembly="MyMigrations.dll" --task=migrate --output --outputFilename="src\migrated.sql"
should have been this:
migrate.exe --conn="Server=.;Database=my_db;Trusted_Connection=True;Encrypt=True;Connection Timeout=30;" --provider=SqlServer --assembly="MyMigrations.dll" --tag="localhost" --task=migrate --output --outputFilename="src\migrated.sql"
NOTE: The --tag
parameter missing in the first script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With