MigrationStage.AfterAll doesn't get executed when registering migrations via .ScanIn(typeof(Program).Assembly).For.Migrations()
See original GitHub issueWhen trying to run a Maintainance script on sql server it doesn’t get executed. I’ve tried to step into the source and it seems like AssemblySourceOptions doesn’t return any assemblies. My entire source is here. I use .net core. What is the problem. I cannot find documentation on this.
My goal is to have all stored proc applied on the database on every single Migrate run - via the class Id_999999999999_RunAllStoredProcedures.
class Program
{
static void Main(string[] args)
{
IServiceCollection services = new ServiceCollection();
const string connectionString = @"Server=.\SQLEXPRESS;Database=Cv;Trusted_Connection=true";
services
.AddFluentMigratorCore()
.ConfigureRunner(
x => x.AddSqlServer2016()
.WithGlobalConnectionString(connectionString)
.ScanIn(typeof(Program).Assembly).For.Migrations());
var provider = services.BuildServiceProvider();
using (IServiceScope scope = provider.CreateScope())
{
IMigrationRunner runner = scope.ServiceProvider.GetRequiredService<IMigrationRunner>();
runner.MigrateUp();
}
}
}
[Migration(1)]
public class TestMigration : Migration
{
/// <inheritdoc />
public override void Up()
{
Create.Table("test").WithColumn("Id").AsString();
}
/// <inheritdoc />
public override void Down()
{
throw new NotImplementedException();
}
}
[Maintenance(MigrationStage.AfterAll)]
public class Id_999999999999_RunAllStoredProcedures : Migration
{
public override void Up()
{
Execute.Sql("CREATE OR ALTER PROC a AS BEGIN SELECT 1 END");
}
public override void Down()
{
//NOOP
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:20 (1 by maintainers)
Top Results From Across the Web
Add migration with different assembly
Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing " ...
Read more >Using a Separate Migrations Project - EF Core
Using a separate migration project for managing database schemas with Entity Framework Core.
Read more >Fix: Your target project doesn't match your migration assembly
In this video, I am going to show you , How to fix that error " Your target project "Projectname" doesn't match your...
Read more >Migrations and Seed Data With Entity Framework Core
We are going to learn about Migrations and Seed data in Entity Framework ... EF Core provides a method called Migrate to execute...
Read more >Applying Migrations - EF Core
Strategies for applying schema migrations to production and development databases using Entity Framework Core.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
https://github.com/jzabroski/FluentMigratorRepro
After following this process, the error still persists what change is I targeted my migration file to be in my .net core API project directory, not the class library project. “It works for me”