1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 00:52:49 -05:00
This commit is contained in:
Michal Checinski
2023-08-17 15:02:49 +02:00
parent 4949c62792
commit e47d544baf
2 changed files with 38 additions and 47 deletions

View File

@ -1,58 +1,56 @@
using System; using System.Data;
using DbUp.Engine;
using DbUp.Engine.Output; using DbUp.Engine.Output;
using DbUp.Engine.Transactions; using DbUp.Engine.Transactions;
using DbUp.Support;
using DbUp.Engine;
using System.Data;
using System.Collections.Generic;
using DbUp.SqlServer; using DbUp.SqlServer;
using DbUp.Support;
namespace Bit.Migrator; namespace Bit.Migrator;
public class RerunableSqlTableJournal : TableJournal public class RerunableSqlTableJournal : TableJournal
{
public RerunableSqlTableJournal(Func<IConnectionManager> connectionManager, Func<IUpgradeLog> logger, string schema, string table)
: base(connectionManager, logger, new SqlServerObjectParser(), schema, table)
{ {
}
public RerunableSqlTableJournal(Func<IConnectionManager> connectionManager, Func<IUpgradeLog> logger, string schema, string table) protected new IDbCommand GetInsertScriptCommand(Func<IDbCommand> dbCommandFactory, SqlScript script)
: base(connectionManager, logger, new SqlServerObjectParser(), schema, table) {
{ var command = dbCommandFactory();
}
protected new IDbCommand GetInsertScriptCommand(Func<IDbCommand> dbCommandFactory, SqlScript script) var scriptNameParam = command.CreateParameter();
{ scriptNameParam.ParameterName = "scriptName";
var command = dbCommandFactory(); scriptNameParam.Value = script.Name;
command.Parameters.Add(scriptNameParam);
var scriptNameParam = command.CreateParameter(); var appliedParam = command.CreateParameter();
scriptNameParam.ParameterName = "scriptName"; appliedParam.ParameterName = "applied";
scriptNameParam.Value = script.Name; appliedParam.Value = DateTime.Now;
command.Parameters.Add(scriptNameParam); command.Parameters.Add(appliedParam);
var appliedParam = command.CreateParameter(); command.CommandText = GetInsertJournalEntrySql("@scriptName", "@applied");
appliedParam.ParameterName = "applied"; command.CommandType = CommandType.Text;
appliedParam.Value = DateTime.Now; return command;
command.Parameters.Add(appliedParam); }
command.CommandText = GetInsertJournalEntrySql("@scriptName", "@applied"); protected override string GetInsertJournalEntrySql(string @scriptName, string @applied)
command.CommandType = CommandType.Text; {
return command; return $"insert into {FqSchemaTableName} (ScriptName, Applied) values ({@scriptName}, {@applied})";
} }
protected override string GetInsertJournalEntrySql(string @scriptName, string @applied) protected override string GetJournalEntriesSql()
{ {
return $"insert into {FqSchemaTableName} (ScriptName, Applied) values ({@scriptName}, {@applied})"; return $"select [ScriptName] from {FqSchemaTableName} order by [ScriptName]";
} }
protected override string GetJournalEntriesSql() protected override string CreateSchemaTableSql(string quotedPrimaryKeyName)
{ {
return $"select [ScriptName] from {FqSchemaTableName} order by [ScriptName]"; return
}
protected override string CreateSchemaTableSql(string quotedPrimaryKeyName)
{
return
$@"create table {FqSchemaTableName} ( $@"create table {FqSchemaTableName} (
[Id] int identity(1,1) not null constraint {quotedPrimaryKeyName} primary key, [Id] int identity(1,1) not null constraint {quotedPrimaryKeyName} primary key,
[ScriptName] nvarchar(255) not null, [ScriptName] nvarchar(255) not null,
[Applied] datetime not null [Applied] datetime not null
)"; )";
}
} }
}

View File

@ -1,11 +1,4 @@
using System; using DbUp.Builder;
using System.Data;
using System.Data.SqlClient;
using DbUp;
using DbUp.Builder;
using DbUp.Engine.Output;
using DbUp.Engine.Transactions;
using DbUp.SqlServer;
namespace Bit.Migrator; namespace Bit.Migrator;