From 412b139796c60c001958b114d5ed7b91d4180ed1 Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Sat, 2 Apr 2022 11:24:41 -0400 Subject: [PATCH] adopt more of the migrations conventions --- .../Infrastructure/DatabaseManager.cs | 19 ++++++++----------- .../Interfaces/ISiteMigration.cs | 10 ++++++++++ .../Infrastructure/Interfaces/ISiteUpgrade.cs | 9 --------- ...Attribute.cs => SiteMigrationAttribute.cs} | 4 ++-- .../SiteMigration/ExampleSiteMigration.cs | 18 ++++++++++++++++++ .../SiteUpgrade/ExampleUpgrade.cs | 14 -------------- 6 files changed, 38 insertions(+), 36 deletions(-) create mode 100644 Oqtane.Server/Infrastructure/Interfaces/ISiteMigration.cs delete mode 100644 Oqtane.Server/Infrastructure/Interfaces/ISiteUpgrade.cs rename Oqtane.Server/Infrastructure/Interfaces/{SiteUpgradeAttribute.cs => SiteMigrationAttribute.cs} (78%) create mode 100644 Oqtane.Server/Infrastructure/SiteMigration/ExampleSiteMigration.cs delete mode 100644 Oqtane.Server/Infrastructure/SiteUpgrade/ExampleUpgrade.cs diff --git a/Oqtane.Server/Infrastructure/DatabaseManager.cs b/Oqtane.Server/Infrastructure/DatabaseManager.cs index 9f4a3f43..21726ef2 100644 --- a/Oqtane.Server/Infrastructure/DatabaseManager.cs +++ b/Oqtane.Server/Infrastructure/DatabaseManager.cs @@ -678,11 +678,11 @@ namespace Oqtane.Infrastructure var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies(); foreach (Assembly assembly in assemblies) { - foreach (var type in assembly.GetTypes(typeof(ISiteUpgrade))) + foreach (var type in assembly.GetTypes(typeof(ISiteMigration))) { - if (Attribute.IsDefined(type, typeof(SiteUpgradeAttribute))) + if (Attribute.IsDefined(type, typeof(SiteMigrationAttribute))) { - var attribute = (SiteUpgradeAttribute)Attribute.GetCustomAttribute(type, typeof(SiteUpgradeAttribute)); + var attribute = (SiteMigrationAttribute)Attribute.GetCustomAttribute(type, typeof(SiteMigrationAttribute)); siteupgrades.Add(attribute.AliasName + " " + attribute.Version, type); } } @@ -715,21 +715,18 @@ namespace Oqtane.Infrastructure { try { - var obj = Activator.CreateInstance(upgrade.Value) as ISiteUpgrade; - if (obj.Upgrade(site, alias)) + var obj = Activator.CreateInstance(upgrade.Value) as ISiteMigration; + if (obj != null) { + obj.Up(site, alias); site.Version = version; sites.UpdateSite(site); - logger.Log(alias.SiteId, Shared.LogLevel.Information, "Site Upgrade", LogFunction.Other, "Site Upgraded Successfully To Version {version} For {Alias}", version, alias.Name); - } - else - { - logger.Log(alias.SiteId, Shared.LogLevel.Error, "Site Upgrade", LogFunction.Other, "Site Could Not Be Upgraded Using IUpgradeable Interface {Type} For {Alias} And Version {Version}", upgrade.Value, alias.Name, version); + logger.Log(alias.SiteId, Shared.LogLevel.Information, "Site Migration", LogFunction.Other, "Site Migrated Successfully To Version {version} For {Alias}", version, alias.Name); } } catch (Exception ex) { - logger.Log(alias.SiteId, Shared.LogLevel.Error, "Site Upgrade", LogFunction.Other, "An Error Occurred Executing IUpgradeable Interface {Type} For {Alias} And Version {Version} {Error}", upgrade.Value, alias.Name, version, ex.Message); + logger.Log(alias.SiteId, Shared.LogLevel.Error, "Site Migration", LogFunction.Other, "An Error Occurred Executing Site Migration {Type} For {Alias} And Version {Version} {Error}", upgrade.Value, alias.Name, version, ex.Message); } } } diff --git a/Oqtane.Server/Infrastructure/Interfaces/ISiteMigration.cs b/Oqtane.Server/Infrastructure/Interfaces/ISiteMigration.cs new file mode 100644 index 00000000..6e400aab --- /dev/null +++ b/Oqtane.Server/Infrastructure/Interfaces/ISiteMigration.cs @@ -0,0 +1,10 @@ +using Oqtane.Models; + +namespace Oqtane.Infrastructure +{ + public interface ISiteMigration + { + void Up(Site site, Alias alias); + void Down(Site site, Alias alias); // for future use (if necessary) + } +} diff --git a/Oqtane.Server/Infrastructure/Interfaces/ISiteUpgrade.cs b/Oqtane.Server/Infrastructure/Interfaces/ISiteUpgrade.cs deleted file mode 100644 index 262d5147..00000000 --- a/Oqtane.Server/Infrastructure/Interfaces/ISiteUpgrade.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Oqtane.Models; - -namespace Oqtane.Infrastructure -{ - public interface ISiteUpgrade - { - bool Upgrade(Site site, Alias alias); - } -} diff --git a/Oqtane.Server/Infrastructure/Interfaces/SiteUpgradeAttribute.cs b/Oqtane.Server/Infrastructure/Interfaces/SiteMigrationAttribute.cs similarity index 78% rename from Oqtane.Server/Infrastructure/Interfaces/SiteUpgradeAttribute.cs rename to Oqtane.Server/Infrastructure/Interfaces/SiteMigrationAttribute.cs index 30441e47..8c8aade6 100644 --- a/Oqtane.Server/Infrastructure/Interfaces/SiteUpgradeAttribute.cs +++ b/Oqtane.Server/Infrastructure/Interfaces/SiteMigrationAttribute.cs @@ -3,12 +3,12 @@ using System; namespace Oqtane.Infrastructure { [AttributeUsage(AttributeTargets.Class)] - public class SiteUpgradeAttribute : Attribute + public class SiteMigrationAttribute : Attribute { private string aliasname; private string version; - public SiteUpgradeAttribute(string AliasName, string Version) + public SiteMigrationAttribute(string AliasName, string Version) { aliasname = AliasName; version = Version; diff --git a/Oqtane.Server/Infrastructure/SiteMigration/ExampleSiteMigration.cs b/Oqtane.Server/Infrastructure/SiteMigration/ExampleSiteMigration.cs new file mode 100644 index 00000000..cb191c81 --- /dev/null +++ b/Oqtane.Server/Infrastructure/SiteMigration/ExampleSiteMigration.cs @@ -0,0 +1,18 @@ +using Oqtane.Models; + +namespace Oqtane.Infrastructure +{ + [SiteMigration("localhost:44357", "01.00.00")] + public class ExampleSiteMigration : ISiteMigration + { + void ISiteMigration.Up(Site site, Alias alias) + { + // execute some version-specific upgrade logic for the site here such as adding pages, modules, content, etc... + } + + void ISiteMigration.Down(Site site, Alias alias) + { + // not implemented + } + } +} diff --git a/Oqtane.Server/Infrastructure/SiteUpgrade/ExampleUpgrade.cs b/Oqtane.Server/Infrastructure/SiteUpgrade/ExampleUpgrade.cs deleted file mode 100644 index dde44221..00000000 --- a/Oqtane.Server/Infrastructure/SiteUpgrade/ExampleUpgrade.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Oqtane.Models; - -namespace Oqtane.Infrastructure -{ - [SiteUpgrade("localhost:44357", "01.00.00")] - public class ExampleUpgrade : ISiteUpgrade - { - bool ISiteUpgrade.Upgrade(Site site, Alias alias) - { - // execute some version-specific upgrade logic for the site here such as adding pages, modules, content, etc... - return true; - } - } -}