diff --git a/.gitignore b/.gitignore index 84cfa08..9ab9fb0 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ OADSI.exe.config *.sqlproj.user *.orig *.nupkg +/.vs diff --git a/Source/Improving.DbUp/DbUpdater.cs b/Source/Improving.DbUp/DbUpdater.cs index 7f9e8e4..40d2ac6 100644 --- a/Source/Improving.DbUp/DbUpdater.cs +++ b/Source/Improving.DbUp/DbUpdater.cs @@ -20,26 +20,32 @@ public class DbUpdater private readonly Assembly _migrationAssembly; private readonly bool _seedData; private readonly Env _env; + private readonly string _versionTableSchema; + private readonly string _versionTableName; - public DbUpdater(Assembly migrationAssembly, + public DbUpdater(Assembly migrationAssembly, string folderName, string databaseName, string connectionStringName, IDictionary scriptVariables, bool SeedData = false, - Env env = Env.Undefined) + Env env = Env.Undefined, + string versionTableName = HashedSqlServerExtensions.VersionTableName, + string versionTableSchema = null) { - _namespacePrefix = migrationAssembly.GetName().Name + "."; - _migrationAssembly = migrationAssembly; - _seedData = SeedData; - _env = env; + _namespacePrefix = migrationAssembly.GetName().Name + "."; + _migrationAssembly = migrationAssembly; + _seedData = SeedData; + _env = env; + _versionTableName = versionTableName; + _versionTableSchema = versionTableSchema; ConnectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString + ";App=" + databaseName + "Migrations"; UseTransactions = true; DatabaseName = databaseName; FolderName = folderName; ScriptVariables = scriptVariables; - } + } public string FolderName { get; } public string DatabaseName { get; } @@ -165,7 +171,8 @@ private void ExecuteDatabaseActions(string scriptPrefix, string connectionString .WithExecutionTimeout(TimeSpan.FromSeconds(2147483647)) .WithScriptsEmbeddedInAssembly(_migrationAssembly, name => name.StartsWith(scriptPrefix)) - .WithVariables(ScriptVariables) + .JournalToSqlTable(_versionTableSchema, _versionTableName) + .WithVariables(ScriptVariables) .LogToConsole(); PerformUpgrade(customBuilderTransform, builder); @@ -195,11 +202,11 @@ private void ExecuteHashedDatabaseActions(string scriptPrefix, string connection { var sqlConnectionManager = new SqlConnectionManager(connectionString); var log = new ConsoleUpgradeLog(); - var journal = new HashedSqlTableJournal(() => sqlConnectionManager, () => log, null, HashedSqlServerExtensions.VersionTableName); + var journal = new HashedSqlTableJournal(() => sqlConnectionManager, () => log, _versionTableSchema, _versionTableName); var builder = DeployChanges.To - .HashedSqlDatabase(sqlConnectionManager) + .HashedSqlDatabase(sqlConnectionManager, _versionTableSchema, _versionTableName) .WithExecutionTimeout(TimeSpan.FromSeconds(2147483647)) .WithHashedScriptsEmbeddedInAssembly(_migrationAssembly, name => name.StartsWith(scriptPrefix), journal) .WithVariables(ScriptVariables) diff --git a/Source/Improving.DbUp/Hashed/HashedSqlServerExtensions.cs b/Source/Improving.DbUp/Hashed/HashedSqlServerExtensions.cs index a11ed2a..1476d2f 100644 --- a/Source/Improving.DbUp/Hashed/HashedSqlServerExtensions.cs +++ b/Source/Improving.DbUp/Hashed/HashedSqlServerExtensions.cs @@ -11,12 +11,12 @@ public static class HashedSqlServerExtensions { public const string VersionTableName = "SchemaVersions"; - public static UpgradeEngineBuilder HashedSqlDatabase(this SupportedDatabases supported, SqlConnectionManager connectionManager) + public static UpgradeEngineBuilder HashedSqlDatabase(this SupportedDatabases supported, SqlConnectionManager connectionManager, string versionTableSchema, string versionTableName) { var builder = new UpgradeEngineBuilder(); builder.Configure(c => c.ConnectionManager = connectionManager); - builder.Configure(c => c.ScriptExecutor = new SqlScriptExecutor(() => c.ConnectionManager, () => c.Log, null, () => c.VariablesEnabled, c.ScriptPreprocessors)); - builder.Configure(c => c.Journal = new HashedSqlTableJournal(() => c.ConnectionManager, () => c.Log, null, VersionTableName)); + builder.Configure(c => c.ScriptExecutor = new SqlScriptExecutor(() => c.ConnectionManager, () => c.Log, versionTableSchema, () => c.VariablesEnabled, c.ScriptPreprocessors)); + builder.Configure(c => c.Journal = new HashedSqlTableJournal(() => c.ConnectionManager, () => c.Log, versionTableSchema, versionTableName)); return builder; }