mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 00:52:49 -05:00
Move RerunableSqlTableJournal to Extension class
This commit is contained in:
@ -1,56 +0,0 @@
|
|||||||
using System.Data;
|
|
||||||
using DbUp.Engine;
|
|
||||||
using DbUp.Engine.Output;
|
|
||||||
using DbUp.Engine.Transactions;
|
|
||||||
using DbUp.SqlServer;
|
|
||||||
using DbUp.Support;
|
|
||||||
|
|
||||||
namespace Bit.Migrator;
|
|
||||||
|
|
||||||
public class RerunableSqlTableJournal : TableJournal
|
|
||||||
{
|
|
||||||
|
|
||||||
public RerunableSqlTableJournal(Func<IConnectionManager> connectionManager, Func<IUpgradeLog> logger, string schema, string table)
|
|
||||||
: base(connectionManager, logger, new SqlServerObjectParser(), schema, table)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected new IDbCommand GetInsertScriptCommand(Func<IDbCommand> dbCommandFactory, SqlScript script)
|
|
||||||
{
|
|
||||||
var command = dbCommandFactory();
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
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 GetJournalEntriesSql()
|
|
||||||
{
|
|
||||||
return $"select [ScriptName] from {FqSchemaTableName} order by [ScriptName]";
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
)";
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,3 +10,51 @@ public static class SqlTableJournalExtensions
|
|||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class RerunableSqlTableJournal : TableJournal
|
||||||
|
{
|
||||||
|
|
||||||
|
public RerunableSqlTableJournal(Func<IConnectionManager> connectionManager, Func<IUpgradeLog> logger, string schema, string table)
|
||||||
|
: base(connectionManager, logger, new SqlServerObjectParser(), schema, table)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected new IDbCommand GetInsertScriptCommand(Func<IDbCommand> dbCommandFactory, SqlScript script)
|
||||||
|
{
|
||||||
|
var command = dbCommandFactory();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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 GetJournalEntriesSql()
|
||||||
|
{
|
||||||
|
return $"select [ScriptName] from {FqSchemaTableName} order by [ScriptName]";
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user