diff --git a/util/Migrator/RerunableSqlTableJournal.cs b/util/Migrator/RerunableSqlTableJournal.cs index fa2a709f83..34eedd8344 100644 --- a/util/Migrator/RerunableSqlTableJournal.cs +++ b/util/Migrator/RerunableSqlTableJournal.cs @@ -1,58 +1,56 @@ -using System; +using System.Data; +using DbUp.Engine; using DbUp.Engine.Output; using DbUp.Engine.Transactions; -using DbUp.Support; -using DbUp.Engine; -using System.Data; -using System.Collections.Generic; using DbUp.SqlServer; +using DbUp.Support; namespace Bit.Migrator; - public class RerunableSqlTableJournal : TableJournal +public class RerunableSqlTableJournal : TableJournal +{ + + public RerunableSqlTableJournal(Func connectionManager, Func logger, string schema, string table) + : base(connectionManager, logger, new SqlServerObjectParser(), schema, table) { + } - public RerunableSqlTableJournal(Func connectionManager, Func logger, string schema, string table) - : base(connectionManager, logger, new SqlServerObjectParser(), schema, table) - { - } + protected new IDbCommand GetInsertScriptCommand(Func dbCommandFactory, SqlScript script) + { + var command = dbCommandFactory(); - protected new IDbCommand GetInsertScriptCommand(Func dbCommandFactory, SqlScript script) - { - var command = dbCommandFactory(); + var scriptNameParam = command.CreateParameter(); + scriptNameParam.ParameterName = "scriptName"; + scriptNameParam.Value = script.Name; + command.Parameters.Add(scriptNameParam); - var scriptNameParam = command.CreateParameter(); - scriptNameParam.ParameterName = "scriptName"; - scriptNameParam.Value = script.Name; - command.Parameters.Add(scriptNameParam); + var appliedParam = command.CreateParameter(); + appliedParam.ParameterName = "applied"; + appliedParam.Value = DateTime.Now; + command.Parameters.Add(appliedParam); - var appliedParam = command.CreateParameter(); - appliedParam.ParameterName = "applied"; - appliedParam.Value = DateTime.Now; - command.Parameters.Add(appliedParam); + command.CommandText = GetInsertJournalEntrySql("@scriptName", "@applied"); + command.CommandType = CommandType.Text; + return command; + } - command.CommandText = GetInsertJournalEntrySql("@scriptName", "@applied"); - command.CommandType = CommandType.Text; - return command; - } + protected override string GetInsertJournalEntrySql(string @scriptName, string @applied) + { + return $"insert into {FqSchemaTableName} (ScriptName, Applied) values ({@scriptName}, {@applied})"; + } - protected override string GetInsertJournalEntrySql(string @scriptName, string @applied) - { - return $"insert into {FqSchemaTableName} (ScriptName, Applied) values ({@scriptName}, {@applied})"; - } + protected override string GetJournalEntriesSql() + { + return $"select [ScriptName] from {FqSchemaTableName} order by [ScriptName]"; + } - protected override string GetJournalEntriesSql() - { - return $"select [ScriptName] from {FqSchemaTableName} order by [ScriptName]"; - } - - protected override string CreateSchemaTableSql(string quotedPrimaryKeyName) - { - return + protected override string CreateSchemaTableSql(string quotedPrimaryKeyName) + { + return $@"create table {FqSchemaTableName} ( [Id] int identity(1,1) not null constraint {quotedPrimaryKeyName} primary key, [ScriptName] nvarchar(255) not null, [Applied] datetime not null )"; - } } +} diff --git a/util/Migrator/RerunableSqlTableJournalExtensions.cs b/util/Migrator/RerunableSqlTableJournalExtensions.cs index c7f78f6ed2..1a56c77da3 100644 --- a/util/Migrator/RerunableSqlTableJournalExtensions.cs +++ b/util/Migrator/RerunableSqlTableJournalExtensions.cs @@ -1,11 +1,4 @@ -using System; -using System.Data; -using System.Data.SqlClient; -using DbUp; -using DbUp.Builder; -using DbUp.Engine.Output; -using DbUp.Engine.Transactions; -using DbUp.SqlServer; +using DbUp.Builder; namespace Bit.Migrator; @@ -16,4 +9,4 @@ public static class RerunableSqlTableJournalExtensions builder.Configure(c => c.Journal = new RerunableSqlTableJournal(() => c.ConnectionManager, () => c.Log, schema, table)); return builder; } -} \ No newline at end of file +}