简体   繁体   中英

How to add begin transaction and rollback transaction in preview sql script using FluentMigration?

I'm using FluentMigrator for my .Net project and I want to create a sql script to preview my modification when calling dotnet fm migrate command.

Unfortunately, we didn't have the "begin transaction" and "rollback transaction" in the preview script generated. We used to have these commands in the script some months ago based on our old files.

Could you please tell me if I miss something in the command line ?

Thanks in advance, Cheers, Alex

dotnet fm migrate -p sqlserver2012 -a "mydll.dll" -c "Data Source=mydatasource" -o="Migrations/MigrationScript.sql" -V --preview

one way to begin a transaction is this:

internal static void MigrateUp()
{
    var serviceProvider = CreateServices();

    // Put the database update into a scope to ensure
    // that all resources will be disposed.
    using (var scope = serviceProvider.CreateScope())
    {
        // Instantiate the runner
        var runner = serviceProvider.GetRequiredService<IMigrationRunner>();

        using(var runnerScope = runner.BeginScope())
        {
            try
            {
                runner.MigrateUp();
                runnerScope.Complete();
            }
            catch(Exception ex)
            {
                runnerScope.Cancel();
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM