mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 00:52:49 -05:00
Add rerunable schema
This commit is contained in:
@ -10,19 +10,21 @@ namespace Bit.Migrator;
|
|||||||
|
|
||||||
public static class SqlTableJournalExtensions
|
public static class SqlTableJournalExtensions
|
||||||
{
|
{
|
||||||
public static UpgradeEngineBuilder JournalRerunableToSqlTable(this UpgradeEngineBuilder builder, string schema, string table)
|
public static UpgradeEngineBuilder JournalRerunableToSqlTable(this UpgradeEngineBuilder builder, string schema, string table, bool rerunable = false)
|
||||||
{
|
{
|
||||||
builder.Configure(c => c.Journal = new RerunableSqlTableJournal(() => c.ConnectionManager, () => c.Log, schema, table));
|
builder.Configure(c => c.Journal = new RerunableSqlTableJournal(() => c.ConnectionManager, () => c.Log, schema, table, rerunable));
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RerunableSqlTableJournal : TableJournal
|
public class RerunableSqlTableJournal : SqlTableJournal
|
||||||
{
|
{
|
||||||
|
private bool Rerunable { get; set; }
|
||||||
|
|
||||||
public RerunableSqlTableJournal(Func<IConnectionManager> connectionManager, Func<IUpgradeLog> logger, string schema, string table)
|
public RerunableSqlTableJournal(Func<IConnectionManager> connectionManager, Func<IUpgradeLog> logger, string schema, string table, bool rerunable = false)
|
||||||
: base(connectionManager, logger, new SqlServerObjectParser(), schema, table)
|
: base(connectionManager, logger, schema, table)
|
||||||
{
|
{
|
||||||
|
Rerunable = rerunable;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected new IDbCommand GetInsertScriptCommand(Func<IDbCommand> dbCommandFactory, SqlScript script)
|
protected new IDbCommand GetInsertScriptCommand(Func<IDbCommand> dbCommandFactory, SqlScript script)
|
||||||
@ -39,19 +41,24 @@ public class RerunableSqlTableJournal : TableJournal
|
|||||||
appliedParam.Value = DateTime.Now;
|
appliedParam.Value = DateTime.Now;
|
||||||
command.Parameters.Add(appliedParam);
|
command.Parameters.Add(appliedParam);
|
||||||
|
|
||||||
command.CommandText = GetInsertJournalEntrySql("@scriptName", "@applied");
|
var rerunableParam = command.CreateParameter();
|
||||||
|
rerunableParam.ParameterName = "rerunable";
|
||||||
|
rerunableParam.Value = Rerunable;
|
||||||
|
command.Parameters.Add(rerunableParam);
|
||||||
|
|
||||||
|
command.CommandText = GetInsertJournalEntrySql("@scriptName", "@applied", "@rerrunable");
|
||||||
command.CommandType = CommandType.Text;
|
command.CommandType = CommandType.Text;
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetInsertJournalEntrySql(string @scriptName, string @applied)
|
protected override string GetInsertJournalEntrySql(string @scriptName, string @applied, string @rerrunable)
|
||||||
{
|
{
|
||||||
return $"insert into {FqSchemaTableName} (ScriptName, Applied) values ({@scriptName}, {@applied})";
|
return $"insert into {FqSchemaTableName} (ScriptName, Applied, Rerunable) values ({@scriptName}, {@applied}, {@rerrunable})";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetJournalEntriesSql()
|
protected override string GetJournalEntriesSql()
|
||||||
{
|
{
|
||||||
return $"select [ScriptName] from {FqSchemaTableName} order by [ScriptName]";
|
return $"select [ScriptName] from {FqSchemaTableName} where [Rerunable] = 0 order by [ScriptName]";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string CreateSchemaTableSql(string quotedPrimaryKeyName)
|
protected override string CreateSchemaTableSql(string quotedPrimaryKeyName)
|
||||||
@ -60,7 +67,8 @@ public class RerunableSqlTableJournal : TableJournal
|
|||||||
$@"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,
|
||||||
|
[Rerunable] bit not null DEFAULT 0
|
||||||
)";
|
)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user