Skip to content

Commit

Permalink
Merge pull request #2108 from HicServices/task/RDMP-236-improved-db-u…
Browse files Browse the repository at this point in the history
…pdates

Task/RDMP-236 Simplify UII DB Patching Process
  • Loading branch information
rdteviotdale authored Jan 6, 2025
2 parents 188afdb + fcd7892 commit af31d64
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

- Build on and target .Net 9 rather than 8
- Simplify DB Patching Interface

## [8.4.2] - 2024-12-18

- Fix issue with MEF constructing Remote Table Attachers
Expand Down
8 changes: 4 additions & 4 deletions Rdmp.UI/TestsAndSetup/StartupUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ private void HandleDatabaseFoundOnSimpleUI(PlatformDatabaseFoundEventArgs eventA

case RDMPPlatformDatabaseStatus.RequiresPatching:

if (MessageBox.Show($"Patching Required on database of type {eventArgs.Patcher.Name}", "Patch",
MessageBoxButtons.YesNo) == DialogResult.Yes)
if (MessageBox.Show($"Patching Required on database of type {eventArgs.Patcher.Name}", "Patch RDMP",
MessageBoxButtons.OKCancel) == DialogResult.OK)
{
PatchingUI.ShowIfRequired(
eventArgs.Repository.DiscoveredServer.GetCurrentDatabase(),
Expand All @@ -275,8 +275,8 @@ private void HandleDatabaseFoundOnSimpleUI(PlatformDatabaseFoundEventArgs eventA
}
else
{
MessageBox.Show("Patching was cancelled, application will exit");
Application.Exit();
MessageBox.Show("Patching was cancelled. Apply Patch to use the latest version of RDMP. Application will exit.");
Environment.Exit(0);
}

break;
Expand Down
30 changes: 6 additions & 24 deletions Rdmp.UI/Versioning/PatchingUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ public partial class PatchingUI : Form
private readonly DiscoveredDatabase _database;
private readonly ITableRepository _repository;

private bool _yesToAll;
private IPatcher _patcher;

private PatchingUI(DiscoveredDatabase database, ITableRepository repository, IPatcher patcher)
{
_database = database;
_repository = repository;
_patcher = patcher;

InitializeComponent();

this.btnAttemptPatching.Enabled = false;
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
return;

Expand All @@ -57,6 +55,8 @@ private PatchingUI(DiscoveredDatabase database, ITableRepository repository, IPa
{
tbDatabase.Text = $"{_database.GetRuntimeName()}, Version:{repository.GetVersion()}";
}
btnAttemptPatching_Click(null, null);

}

private void btnAttemptPatching_Click(object sender, EventArgs e)
Expand All @@ -68,8 +68,8 @@ private void btnAttemptPatching_Click(object sender, EventArgs e)
var mds = new MasterDatabaseScriptExecutor(_database);


mds.PatchDatabase(_patcher, toMem, PreviewPatch,
() => MessageBox.Show("Backup Database First", "Backup", MessageBoxButtons.YesNo) == DialogResult.Yes);
mds.PatchDatabase(_patcher, toMem, (Patch p) => true,
() => false);

//if it crashed during patching
if (toMem.GetWorst() == CheckResult.Fail)
Expand All @@ -92,7 +92,7 @@ private void btnAttemptPatching_Click(object sender, EventArgs e)

checksUI1.OnCheckPerformed(new CheckEventArgs("Patching Successful", CheckResult.Success, null));

if (MessageBox.Show("Application will now restart", "Close?", MessageBoxButtons.YesNo) == DialogResult.Yes)
if (MessageBox.Show("Application will now restart", "Restart Application", MessageBoxButtons.OK) == DialogResult.OK)
ApplicationRestarter.Restart();
}
catch (Exception exception)
Expand All @@ -106,22 +106,4 @@ public static void ShowIfRequired(DiscoveredDatabase database, ITableRepository
if (Patch.IsPatchingRequired(database, patcher, out _, out _, out _) == Patch.PatchingState.Required)
new PatchingUI(database, repository, patcher).ShowDialog();
}


private bool PreviewPatch(Patch patch)
{
if (_yesToAll)
return true;

var preview = new SQLPreviewWindow(patch.locationInAssembly, "The following SQL Patch will be run:",
patch.GetScriptBody());
try
{
return preview.ShowDialog() == DialogResult.OK;
}
finally
{
_yesToAll = preview.YesToAll;
}
}
}

0 comments on commit af31d64

Please sign in to comment.