internal DbUpgrade(string connectionString) { _upgradeEngine = DeployChanges.To .SQLiteDatabase(connectionString) .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly()) .Build(); }
public static int Main(string[] args) { string connectionString = Configuration["ConnectionStrings:PrimarySchoolDB"]; EnsureDatabase.For.SqlDatabase(connectionString); UpgradeEngine upgrader = DeployChanges.To .SqlDatabase(connectionString) .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly()) .LogToConsole() .Build(); DatabaseUpgradeResult result = upgrader.PerformUpgrade(); if (!result.Successful) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(result.Error); Console.ResetColor(); return(-1); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Success!"); Console.ResetColor(); return(0); }
private static DatabaseUpgradeResult RunDatabaseUpdate(string connectionString, bool dropDatabase) { if (dropDatabase) { DropDatabase.For.PostgresqlDatabase(connectionString); } EnsureDatabase.For.PostgresqlDatabase(connectionString); UpgradeEngine upgradeEngine = DeployChanges .To .PostgresqlDatabase(connectionString) .WithScriptsFromFileSystem ( SRC_PATH, new FileSystemScriptOptions { IncludeSubDirectories = true } ) .WithTransactionPerScript() .WithVariablesDisabled() .Build(); return(upgradeEngine.PerformUpgrade()); }
private static bool FinishUpgrade(UpgradeEngine upgrader, ILog log) { var toExecute = upgrader.GetScriptsToExecute(); log.WriteLine("Upgrading File..."); log.WriteLine($"Applying {toExecute.Count} scripts."); var result = upgrader.PerformUpgrade(); if (!result.Successful) { log.WriteLine("Upgrage failed!", LogLevel.Error); log.WriteLine(result.Error.ToString(), LogLevel.Error); return(false); } log.WriteLine("Upgrade successful!"); foreach (SqlScript script in result.Scripts) { log.WriteLine($"Applied Upgrade Script {script.Name}."); } log.WriteLine(); return(true); }
private static void GenerateReport(string destinationDir, UpgradeEngine upgrader) { var fullReportPath = Path.Combine(destinationDir, "UpgradeReport.html"); Console.WriteLine($"Generating the report at {fullReportPath}"); upgrader.GenerateUpgradeHtmlReport(fullReportPath); }
public static void RunDBMigration() { UpgradeEngine upgradeEngine = DeployChanges.To .PostgresqlDatabase(GetConnectionString()) .WithScriptsFromFileSystem("sqlScriptDirectory") .LogToConsole() .Build(); }
public virtual void AfterEach() { ScriptProvider = null; VersionTracker = null; ScriptExecutor = null; Log = null; DbUpgrader = null; }
/// <summary> /// Performs the upgrade. /// </summary> /// <param name="upgradeEngine">The upgrade engine.</param> /// <param name="sqlVerify">The SQL verify.</param> public static void PerformUpgrade(this UpgradeEngine upgradeEngine, ISqlVerify sqlVerify) { var result = upgradeEngine.PerformUpgrade(); if (result.Successful) { sqlVerify.UpdateDb(); } }
private void GivenAnUpToDateDatabase() { var journal = GetJournal(); journal.StoreExecutedScript(scripts[0]); journal.StoreExecutedScript(scripts[1]); journal.StoreExecutedScript(scripts[2]); upgradeEngine = upgradeEngineBuilder.Build(); }
/// <summary> /// Initializes a new instance of the <see cref="Migrator"/> class. /// </summary> /// <param name="configuration">Application configuration for configuring services.</param> /// <param name="assemblies">The assemblies where there are migration scripts to run.</param> /// <param name="upgradeLog">The logger instance for DbUp.</param> public Migrator(IConfiguration configuration, IEnumerable <Assembly> assemblies, IUpgradeLog upgradeLog) { this.upgradeEngine = DeployChanges.To.PostgresqlDatabase(configuration.GetConnectionString("MandarinConnection")) .WithScriptsEmbeddedInAssemblies(assemblies.ToArray()) .WithTransactionPerScript() .WithScriptNameComparer(new MigrationIdComparer()) .WithVariable("FixedCommissionAmountJson", Migrator.GetFixedCommissionAmountJson(configuration)) .LogTo(upgradeLog) .Build(); }
public DatabaseManager(string connectionName) { _connectionString = System.Configuration.ConfigurationManager.ConnectionStrings[connectionName].ConnectionString; _upgradeEngine = DeployChanges.To .SqlDatabase(_connectionString) .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly()) .LogToConsole() .Build(); }
} // Run private static void GenerateScriptFile(string destinationDir, UpgradeEngine upgrader) { // Generate full script to apply var scriptPath = Path.Combine(destinationDir, "UpgradeScript.sql"); Console.WriteLine($"Generating the script {scriptPath}"); File.WriteAllLines(scriptPath, upgrader.GetScriptsToExecute().Select(x => $"-- ### {x.Name}{Environment.NewLine}{x.Contents}"), Encoding.UTF8); }
public static string DryRun(this UpgradeEngine upgradeEngine, IDictionary <string, string> variables) { var buffer = new StringBuilder($"-- DbUp generated script at {DateTimeOffset.Now}\n"); var variableReplacer = new VariableSubstitutionPreprocessor(variables); upgradeEngine.GetScriptsToExecute().ForEach(s => { buffer.AppendLine($"-- Script name: {s.Name}"); buffer.AppendLine(variableReplacer.Process(s.Contents)); }); return(buffer.ToString()); }
/// <summary> /// Executes the engine. /// </summary> /// <param name="engine"> /// The engine. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> private static bool ExecuteEngine(UpgradeEngine engine) { var result = engine.PerformUpgrade(); if (result.Successful == false) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(result.Error); Console.ResetColor(); } return(result.Successful); }
public static DatabaseUpgradeResult DeployTestSeedData(string connectionString) { EnsureDatabase.For.SqlDatabase(connectionString); UpgradeEngine upgrader = DeployChanges.To .SqlDatabase(connectionString) .WithTransactionPerScript() .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly(), (s) => { return(s.Contains("SeedData")); }) .LogToConsole() .Build(); DatabaseUpgradeResult result = upgrader.PerformUpgrade(); return(result); }
private void RunDbUpdate(string connectionString) { DropDatabase.For.SqlDatabase(connectionString); EnsureDatabase.For.SqlDatabase(connectionString); Assembly dbMigrationAssembly = GetDbMigrationAssembly(); UpgradeEngine upgradeEngine = GetUpgradeEngine(dbMigrationAssembly); var result = upgradeEngine.PerformUpgrade(); if (!result.Successful) { throw new Exception(result.ErrorScript.Contents, result.Error); } }
private static void SetupDatabase() { EnsureDatabase.For.SqlDatabase(DataContext.GetDatabaseConnectionString()); UpgradeEngine dbUpgradeEngine = DeployChanges.To.SqlDatabase(DataContext.GetDatabaseConnectionString()) .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly()) .LogToConsole() .Build(); DatabaseUpgradeResult dbUpgradeResult = dbUpgradeEngine.PerformUpgrade(); if (!dbUpgradeResult.Successful) { throw new ApplicationException("Database setup failed", dbUpgradeResult.Error); } }
public static void UseMigration(this IApplicationBuilder app, string connectionString) { DropDatabase.For.SqlDatabase(connectionString); EnsureDatabase.For.SqlDatabase(connectionString); UpgradeEngine upgrader = DeployChanges.To .SqlDatabase(connectionString) .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly()) .LogToConsole() .Build(); DatabaseUpgradeResult result = upgrader.PerformUpgrade(); ShowMessage(result); }
public DbUpDatabaseUpgrader(IConnectionStringProvider connectionStringProvider, ILog logger) { if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (connectionStringProvider == null) { throw new ArgumentNullException(nameof(connectionStringProvider)); } this.connectionStringProvider = connectionStringProvider; this.upgradeEngine = GetDbUpEngine(); this.logger = logger; }
private static int InstallTests(string connectionString) { UpgradeEngine upgradeEngine = DeployChanges .To .SqlDatabase(connectionString) .WithScriptsFromFileSystem(TESTS_PATH, new FileSystemScriptOptions { IncludeSubDirectories = true }) .JournalTo(new NullJournal()) .Build(); DatabaseUpgradeResult databaseUpgradeResult = upgradeEngine.PerformUpgrade(); return(!databaseUpgradeResult.Successful ? ShowError(databaseUpgradeResult.Error) : ShowSuccess()); }
private void DatabasePrepare(string connectionString, string prov) { try { UpgradeEngineBuilder builder = null; if (prov == "System.Data.SqlClient") { EnsureDatabase.For.SqlDatabase(connectionString, this); builder = DeployChanges.To.SqlDatabase(connectionString).WithTransactionPerScript(); } if (prov == "SQLite") { //EnsureDatabase.For gibt es nicht builder = DeployChanges.To.SQLiteDatabase(connectionString) .WithPreprocessor(new SQLiteConverter()).WithTransactionPerScript(); } if (prov == "Npgsql") { EnsureDatabase.For.PostgresqlDatabase(connectionString, this); builder = DeployChanges.To.PostgresqlDatabase(connectionString) .WithPreprocessor(new PostgresConverter()).WithTransactionPerScript(); } UpgradeEngine upgrader = builder.WithScriptsEmbeddedInAssembly(System.Reflection.Assembly.GetExecutingAssembly()) .LogTo(this) .Build(); var result = upgrader.PerformUpgrade(); if (!result.Successful) { AddLogText2(result.Error.Message); } else { AddLogText2("Success!"); } } catch (Exception ex) { AddLogText2("Error preparing database"); AddLogText2(BauerLib.Registry.DbConnection); AddLogText2(ex.Message); } }
public static void UpdateDatabase(string connectionString) { UpgradeEngine runner = DeployChanges .To .PostgresqlDatabase(connectionString) .WithScriptsFromFileSystem("/src/DbScripts") .WithTransactionPerScript() .LogToConsole() .Build(); DatabaseUpgradeResult result = runner.PerformUpgrade(); if (!result.Successful) { throw result.Error; } }
private void Upgrade(UpgradeEngine upgradeEngine) { var scripts = upgradeEngine.GetScriptsToExecute() .Select(s => s.Name) .ToList(); _log.Information( "Going to migrate the SQL database by executing these scripts: {0}", string.Join(", ", scripts)); var result = upgradeEngine.PerformUpgrade(); if (!result.Successful) { throw new SqlMigrationException(scripts, result.Error.Message, result.Error); } }
public static void DbSetup(string connectionString) { UpgradeEngine upgradeEngine = DeployChanges.To .SqlDatabase(connectionString) .WithScriptsEmbeddedInAssembly(typeof(AirportTable).Assembly) .LogToConsole() .Build(); DatabaseUpgradeResult result = upgradeEngine.PerformUpgrade(); if (!result.Successful) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(result.Error); Console.ResetColor(); } }
public bool Migrate() { string connectionString = this.configuration.GetConnectionString(DB_CONNECTION); EnsureDatabase.For.SqlDatabase(connectionString); UpgradeEngine upgradeEngine = DeployChanges.To .SqlDatabase(connectionString) .WithScriptsEmbeddedInAssembly(Assembly.GetAssembly(GetType())) .LogToConsole() .Build(); DatabaseUpgradeResult upgradeResult = upgradeEngine.PerformUpgrade(); return(upgradeResult.Successful); }
private static int PerformUpgrade(UpgradeEngine engine) { var result = engine.PerformUpgrade(); if (!result.Successful) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(result.Error); Console.ResetColor(); return(-1); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Success!"); Console.ResetColor(); return(0); }
public async Task <bool> Upgrade() { upgradeEngine = DeployChanges.To .SqlDatabase(ConnectionInfo.ConnectionString) .WithScriptsEmbeddedInAssembly(this.GetType().Assembly) .LogToConsole() .Build(); EnsureDatabase.For.SqlDatabase(ConnectionInfo.ConnectionString); var result = upgradeEngine.PerformUpgrade(); await CheckAll(); if (result.Successful == false) { throw result.Error; } return(result.Successful); }
static int Main(string[] args) { string connectionString = ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString; UpgradeEngine engine = DeployChanges.To .SqlDatabase(connectionString) .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly()) .LogToConsole() .Build(); if (!engine.IsUpgradeRequired()) { Console.WriteLine("No upgrade required, database is already up to date."); return(0); } return(PerformUpgrade(engine)); }
public void CheckDatabaseVersion() { upgradeEngine = DeployChanges.To .SqlDatabase(ConnectionInfo.ConnectionString) .WithScriptsEmbeddedInAssembly(this.GetType().Assembly) .LogToConsole() .Build(); IsUpgradeRequired = upgradeEngine.IsUpgradeRequired(); if (IsUpgradeRequired.HasValue && IsUpgradeRequired.Value == false) { Status = DatabaseHelperStatusEnum.CelsusDatabaseVersionOk; } if (IsUpgradeRequired.HasValue && IsUpgradeRequired.Value == true) { Status = DatabaseHelperStatusEnum.CelsusDatabaseVersionOld; } //var tr=upgradeEngine.GetScriptsToExecute(); }
public virtual void BeforeEach() { ScriptProvider = Substitute.For <IScriptProvider> (); VersionTracker = Substitute.For <IJournal> (); ScriptExecutor = Substitute.For <IScriptExecutor> (); ScriptPreprocessor = Substitute.For <IScriptPreprocessor>(); Log = Substitute.For <IUpgradeLog> (); var config = new UpgradeConfiguration(); config.ScriptPreprocessors.Add(ScriptPreprocessor); config.ScriptProviders.Add(ScriptProvider); config.ScriptExecutor = ScriptExecutor; config.Journal = VersionTracker; config.Log = Log; DbUpgrader = new UpgradeEngine(config); }