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

前端 未结 2 2027
无人及你
无人及你 2021-02-07 23:55

is there a way to run migrations from within the application itself?

Thanks!

2条回答
  •  甜味超标
    2021-02-08 00:17

    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);
        }
    

提交回复
热议问题