I work with two databases and want to use fluent migrator for it. They're two SQL Databases, which can be on different servers and have different connectionstrings. They have different tables and data. But I have only one Startup and one project. I want to specify on every Migration the used database. How can I manage this? I'm currently trying to solve it with attributes, but I'm not sure if it works somehow:
public class MyAttribute : Attribute
{
public MyAttribute(string name)
{
Name = name;
}
public string Name;
}
[MyAttribute("Database1")]
[Migration(1)]
public class FooScript : Migration
{
public override void Down()
{
Delete.Table("Foo");
}
public override void Up()
{
Create.Table("Foo")
.WithColumn("id").AsInt16().PrimaryKey()
.WithColumn("Body").AsString(4000).NotNullable();
}
}
And in the startup:
services.AddFluentMigratorCore()
.ConfigureRunner(rb => rb
.AddSqlServer()
.WithGlobalConnectionString("")
.ScanIn(typeof(database1).Assembly, typeof(database1).Assembly).For.Migrations())
.Configure<ProcessorOptions>(x =>
{
var connection = typeof(FooScript).GetCustomAttributes(typeof(MyAttribute), true);
var name = "0"; //here I would need the current executing Migration class
switch (name)
{
case "Database1":
x.ConnectionString = Configuration.GetConnectionString("Database1");
break;
case "Database1":
x.ConnectionString = Configuration.GetConnectionString("Database1");
break;
}
})
.BuildServiceProvider();
But it doesn't work. I would need the attribute of the current script to overwrite the database. But proucessorOptions seems not to have those. Is there another solution or another configuration I could overwrite? Any other ideas how I can run fluentmigration with two or more different sql databases?
Theoretically I would end up with a VersionInfo for every database and the current migration for those database. Hopefully that works.