From 731be1fdddf3e172d552f1d072e6e46e80962f94 Mon Sep 17 00:00:00 2001 From: Michal Checinski Date: Fri, 25 Aug 2023 12:40:17 +0200 Subject: [PATCH] Add update from rerunable to not rerunable script --- util/Migrator/SqlTableJournalExtensions.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/util/Migrator/SqlTableJournalExtensions.cs b/util/Migrator/SqlTableJournalExtensions.cs index 114d386be8..0aaf15b4a3 100644 --- a/util/Migrator/SqlTableJournalExtensions.cs +++ b/util/Migrator/SqlTableJournalExtensions.cs @@ -45,15 +45,21 @@ public class RerunableSqlTableJournal : SqlTableJournal rerunableParam.Value = Rerunable; command.Parameters.Add(rerunableParam); - // command.CommandText = GetInsertJournalEntrySql("@scriptName", "@applied"); - command.CommandText = GetInsertJournalEntrySql("@scriptName", "@applied", "@rerrunable"); + command.CommandText = GetInsertJournalEntrySql("@scriptName", "@applied", "@rerunable"); command.CommandType = CommandType.Text; return command; } - protected string GetInsertJournalEntrySql(string @scriptName, string @applied, string @rerrunable) + protected string GetInsertJournalEntrySql(string @scriptName, string @applied, string @rerunable) { - return $"insert into {FqSchemaTableName} (ScriptName, Applied, Rerunable) values ({@scriptName}, {@applied}, {@rerrunable})"; + return $"IF EXISTS (SELECT * FROM {FqSchemaTableName} WHERE Rerunable = 1 AND ScriptName ='{@scriptName}')" + + "BEGIN" + + $"UPDATE {FqSchemaTableName} SET Applied = {@applied}, Rerunable = {@rerunable} WHERE ScriptName = '{@scriptName}'" + + "END" + + "ELSE" + + "BEGIN" + + $"insert into {FqSchemaTableName} (ScriptName, Applied, Rerunable) values ({@scriptName}, {@applied}, {@rerunable})" + + "END"; } protected override string GetJournalEntriesSql()