migratordotnet - Run migrations from within application (w/o nant or build)

為{幸葍}努か 提交于 2019-12-03 05:54:24

I instantiate an instance of the Migrator class, and then you can call member methods like MigrateToLastVersion() or MigrateTo(long versionnr)

Migrator.Migrator m = new Migrator.Migrator ("SqlServer", connectionString, migrationsAssembly)

m.MigrateToLastVersion();

I don't see why not.

Have a look at the nant task http://code.google.com/p/migratordotnet/source/browse/trunk/src/Migrator.NAnt/MigrateTask.cs

Relevant bits are here:

    private void Execute(Assembly asm)
    {
        Migrator mig = new Migrator(Provider, ConnectionString, asm, Trace, new TaskLogger(this));
        mig.DryRun = DryRun;
        if (ScriptChanges)
        {
            using (StreamWriter writer = new StreamWriter(ScriptFile))
            {
                mig.Logger = new SqlScriptFileLogger(mig.Logger, writer);
                RunMigration(mig);
            }
        }
        else
        {
            RunMigration(mig);
        }
    }

    private void RunMigration(Migrator mig)
    {
        if (mig.DryRun)
            mig.Logger.Log("********** Dry run! Not actually applying changes. **********");

        if (_to == -1)
            mig.MigrateToLastVersion();
        else
            mig.MigrateTo(_to);
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!