Beispiel #1
0
 private static void ApplyMigrations()
 {
     var upgrader = DeployChanges
         .To
         .SqlDatabase(GetConnectionString())
         .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
         .LogToConsole()
         .Build();
     migrationResult = upgrader.PerformUpgrade();
 }
 public void SetUp()
 {
     log = Substitute.For<IUpgradeLog>();
     upgradeResult = null;
     scripts = new List<SqlScript>
     {
         new SqlScript("Script1.sql", "create table Foo (Id int identity)"),
         new SqlScript("Script2.sql", "alter table Foo add column Name varchar(255)"),
         new SqlScript("Script3.sql", "insert into Foo (Name) values ('test')")
     };
     database = new TemporarySQLiteDatabase("IntegrationScenarios");
     upgradeEngineBuilder = DeployChanges.To
         .SQLiteDatabase(database.SharedConnection)
         .WithScripts(new TestScriptProvider(scripts))
         .LogTo(log);
 }
Beispiel #3
0
 static void Display(string dbType, DatabaseUpgradeResult result, TimeSpan ts)
 {
     // Display the result
     if (result.Successful)
     {
         Console.ForegroundColor = ConsoleColor.Green;
         Console.WriteLine("Success!");
         Console.WriteLine("{0} Database Upgrade Runtime: {1}", dbType,
             String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10));
         Console.ReadKey();
     }
     else
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine(result.Error);
         Console.ReadKey();
         Console.WriteLine("Failed!");
     }
 }
 public UpgradeModel(DatabaseUpgradeResult[] results, string log)
 {
     Results = results;
     Log = log;
 }
 private void UpgradeIsPerformed()
 {
     result = upgradeEngineBuilder.Build().PerformUpgrade();
 }
Beispiel #6
0
        internal int GetExitCode(DatabaseUpgradeResult result)
        {
            if (!result.Successful)
            {
                logger.Error("An exception occurred while upgrading the database.", result.Error);

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(result.Error);
                Console.ResetColor();
                return -1;
            }
            else
            {
                int count = result.Scripts.Count();

                stopwatch.Stop();
                TimeSpan elapsed = stopwatch.Elapsed;
                string duration = elapsed.ToString("mm':'ss");

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("{0} scripts executed successfully. Done in {1}!", count, duration);
                Console.ResetColor();
                return 0;
            }
        }
 private void WhenDatabaseIsUpgraded()
 {
     upgradeEngine = upgradeEngineBuilder.Build();
     upgradeResult = upgradeEngine.PerformUpgrade();
 }
        public DatabaseUpgradeResult Run(string[] args)
        {
            DatabaseUpgradeResult result = null;
            if (args.Any(a => "--scriptAllDefinitions".Equals(a, StringComparison.InvariantCultureIgnoreCase)))
            {
                result = ScriptAll();
            }
            else
            {
                var scriptsToExecute = m_engine.GetScriptsToExecute();

                if (args.Any(a => "--whatIf".Equals(a, StringComparison.InvariantCultureIgnoreCase)))
                {
                    result = new DatabaseUpgradeResult(null, true, null);

                    this.Log.WriteWarning("WHATIF Mode!");
                    this.Log.WriteWarning("The following scripts would have been executed:");
                    scriptsToExecute.ForEach(r => this.Log.WriteWarning(r.Name));
                }
                else
                {
                    result = m_engine.PerformUpgrade();

                    if (result.Successful
                        && args.Any(a => "--fromconsole".Equals(a, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        this.Log.WriteInformation("Scripting changed database objects...");
                        var scripter = new DbObjectScripter(this.ConnectionString, m_options, this.Log);
                        var scriptorResult = scripter.ScriptMigrationTargets(scriptsToExecute);
                    }
                }
            }

            return result;
        }
 public DatabaseUpgradeFailedException(DatabaseUpgradeResult result)
 {
     Result = result;
 }
 private void WhenDatabaseIsUpgradedToVersion(ScriptVersion scriptVersion)
 {
     upgradeEngine = upgradeEngineBuilder.SetTargetVersion(scriptVersion).Build();
     upgradeResult = upgradeEngine.PerformUpgrade();
 }