Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent to $InitialDatabase when using ScriptUpdate?

The EF migrations Update-Database command accepts the following parameters: -Script -SourceMigration $InitialDatabase. The script generated is idempotent as explained in this article: http://msdn.microsoft.com/en-US/data/jj591621

Is there an equivalent parameter when using the ScriptUpdate method of the MigratorScriptingDecorator class?

like image 282
cmesyngi Avatar asked Sep 02 '26 11:09

cmesyngi


1 Answers

I also struggled with the same, but it turns out you just have to provide "0".

Example function:

    public static string CreateUpdateScript(DbMigrationsConfiguration config, string sourceMigration, string targetMigration)
    {
        var migrator = new DbMigrator(config);
        var scripter = new MigratorScriptingDecorator(migrator);
        return scripter.ScriptUpdate(sourceMigration, targetMigration);
    }

Then call it like this:

    CreateUpdateScript(new Configuration(), sourceMigration: "0", targetMigration: null);
like image 100
KorsG Avatar answered Sep 05 '26 15:09

KorsG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!