Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for configuring journaling location. #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ OADSI.exe.config
*.sqlproj.user
*.orig
*.nupkg
/.vs
27 changes: 17 additions & 10 deletions Source/Improving.DbUp/DbUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> 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; }
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions Source/Improving.DbUp/Hashed/HashedSqlServerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down