Page IsClickable column must be nullable in order to support upgrades, add more defensive logic

This commit is contained in:
Shaun Walker 2021-06-24 07:41:34 -04:00
parent bfafffd8cb
commit 8e7b553ca8
6 changed files with 56 additions and 34 deletions

View File

@ -17,6 +17,7 @@ using Oqtane.Repository;
using Oqtane.Shared; using Oqtane.Shared;
using Oqtane.Enums; using Oqtane.Enums;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Diagnostics;
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable ConvertToUsingDeclaration // ReSharper disable ConvertToUsingDeclaration
@ -55,16 +56,25 @@ namespace Oqtane.Infrastructure
{ {
try try
{ {
// verify master database contains a Tenant table ( ie. validate schema is properly provisioned )
var provisioned = db.Tenant.Any(); var provisioned = db.Tenant.Any();
} }
catch catch (Exception ex)
{ {
result.Message = "Master Database Not Installed Correctly"; result.Message = "Master Database Not Installed Correctly. " + ex.Message;
} }
} }
else else // cannot connect
{ {
result.Message = "Cannot Connect To Master Database"; try
{
// get the actual connection error details
db.Database.OpenConnection();
}
catch (Exception ex)
{
result.Message = "Cannot Connect To Master Database. " + ex.Message;
}
} }
} }
} }
@ -127,6 +137,7 @@ namespace Oqtane.Infrastructure
{ {
if (!string.IsNullOrEmpty(installation.Message)) if (!string.IsNullOrEmpty(installation.Message))
{ {
Debug.WriteLine($"Oqtane Error: {installation.Message}");
// problem with prior installation // problem with prior installation
install.ConnectionString = ""; install.ConnectionString = "";
} }

View File

@ -5,7 +5,9 @@ using Newtonsoft.Json;
using Oqtane.Models; using Oqtane.Models;
using Oqtane.Repository; using Oqtane.Repository;
using Oqtane.Shared; using Oqtane.Shared;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -48,21 +50,25 @@ namespace Oqtane.Infrastructure
} }
} }
/// <summary>
/// **Note: this code is commented out on purpose - it provides an example of how to programmatically add a page to all existing sites on upgrade
/// </summary>
/// <param name="tenant"></param>
/// <param name="scope"></param>
private void Upgrade_1_0_0(Tenant tenant, IServiceScope scope) private void Upgrade_1_0_0(Tenant tenant, IServiceScope scope)
{ {
var pageTemplates = new List<PageTemplate>(); //var pageTemplates = new List<PageTemplate>();
//
// **Note: this code is commented out on purpose - it provides an example of how to programmatically add a page to all existing sites on upgrade
//pageTemplates.Add(new PageTemplate //pageTemplates.Add(new PageTemplate
//{ //{
// Name = "Test", // Name = "Test",
// Parent = "", // Parent = "",
// Order = 1,
// Path = "test", // Path = "test",
// Icon = Icons.Badge, // Icon = Icons.Badge,
// IsNavigation = true, // IsNavigation = true,
// IsPersonalizable = false, // IsPersonalizable = false,
// EditMode = false, // IsClickable = true,
// PagePermissions = new List<Permission> // PagePermissions = new List<Permission>
// { // {
// new Permission(PermissionNames.View, RoleNames.Admin, true), // new Permission(PermissionNames.View, RoleNames.Admin, true),
@ -84,8 +90,15 @@ namespace Oqtane.Infrastructure
// } // }
// } // }
//}); //});
//
CreateSitePages(scope, pageTemplates); //if (pageTemplates.Count != 0)
//{
// var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
// foreach (Site site in sites.GetSites().ToList())
// {
// sites.CreatePages(site, pageTemplates);
// }
//}
} }
private void Upgrade_2_0_2(Tenant tenant, IServiceScope scope) private void Upgrade_2_0_2(Tenant tenant, IServiceScope scope)
@ -100,19 +113,28 @@ namespace Oqtane.Infrastructure
{ {
Directory.Delete(internalTemplatePath, true); Directory.Delete(internalTemplatePath, true);
} }
catch catch (Exception ex)
{ {
// error deleting directory // error deleting directory
Debug.WriteLine($"Oqtane Error: Error In 2.0.2 Upgrade Logic - {ex}");
} }
} }
} }
// initialize SiteGuid // initialize SiteGuid
var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>(); try
foreach (Site site in sites.GetSites().ToList())
{ {
site.SiteGuid = System.Guid.NewGuid().ToString(); var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
sites.UpdateSite(site); foreach (Site site in sites.GetSites().ToList())
{
site.SiteGuid = System.Guid.NewGuid().ToString();
sites.UpdateSite(site);
}
}
catch (Exception ex)
{
// error populating guid
Debug.WriteLine($"Oqtane Error: Error In 2.0.2 Upgrade Logic - {ex}");
} }
} }
@ -128,16 +150,5 @@ namespace Oqtane.Infrastructure
} }
} }
private void CreateSitePages(IServiceScope scope, List<PageTemplate> pageTemplates)
{
if (pageTemplates.Count != 0)
{
var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
foreach (Site site in sites.GetSites().ToList())
{
sites.CreatePages(site, pageTemplates);
}
}
}
} }
} }

View File

@ -45,9 +45,9 @@ namespace Oqtane.Migrations.EntityBuilders
return ActiveDatabase.AddAutoIncrementColumn(table, RewriteName(name)); return ActiveDatabase.AddAutoIncrementColumn(table, RewriteName(name));
} }
public void AddBooleanColumn(string name) public void AddBooleanColumn(string name, bool nullable = false)
{ {
_migrationBuilder.AddColumn<bool>(RewriteName(name), RewriteName(EntityTableName)); _migrationBuilder.AddColumn<bool>(RewriteName(name), RewriteName(EntityTableName), nullable: nullable);
} }
protected OperationBuilder<AddColumnOperation> AddBooleanColumn(ColumnsBuilder table, string name, bool nullable = false) protected OperationBuilder<AddColumnOperation> AddBooleanColumn(ColumnsBuilder table, string name, bool nullable = false)
@ -85,7 +85,7 @@ namespace Oqtane.Migrations.EntityBuilders
return table.Column<int>(name: RewriteName(name), nullable: nullable); return table.Column<int>(name: RewriteName(name), nullable: nullable);
} }
public void AddMaxStringColumn(string name, int length, bool nullable = false, bool unicode = true) public void AddMaxStringColumn(string name, bool nullable = false, bool unicode = true)
{ {
_migrationBuilder.AddColumn<string>(RewriteName(name), RewriteName(EntityTableName), nullable: nullable, unicode: unicode); _migrationBuilder.AddColumn<string>(RewriteName(name), RewriteName(EntityTableName), nullable: nullable, unicode: unicode);
} }

View File

@ -7,7 +7,7 @@ using Oqtane.Repository;
namespace Oqtane.Migrations.Tenant namespace Oqtane.Migrations.Tenant
{ {
[DbContext(typeof(TenantDBContext))] [DbContext(typeof(TenantDBContext))]
[Migration("Tenant.02.01.01.00")] [Migration("Tenant.02.02.00.01")]
public class AddPageIsClickable : MultiDatabaseMigration public class AddPageIsClickable : MultiDatabaseMigration
{ {
public AddPageIsClickable(IDatabase database) : base(database) public AddPageIsClickable(IDatabase database) : base(database)
@ -18,7 +18,7 @@ namespace Oqtane.Migrations.Tenant
{ {
var pageEntityBuilder = new PageEntityBuilder(migrationBuilder, ActiveDatabase); var pageEntityBuilder = new PageEntityBuilder(migrationBuilder, ActiveDatabase);
pageEntityBuilder.AddBooleanColumn("IsClickable"); pageEntityBuilder.AddBooleanColumn("IsClickable", true);
pageEntityBuilder.UpdateColumn("IsClickable", "1"); pageEntityBuilder.UpdateColumn("IsClickable", "1");
} }

View File

@ -11,7 +11,7 @@ IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.SchemaVersion
) )
END END
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion) INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion)
VALUES ('Master.01.00.00.00', '5.0.0', SYSDATETIME(), '{{Version}}') VALUES ('Master.01.00.00.00', '5.0.4', SYSDATETIME(), '{{Version}}')
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion) INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion)
SELECT REPLACE(REPLACE(ScriptName, 'Oqtane.Scripts.', ''), '.sql', '') As MigrationId, SELECT REPLACE(REPLACE(ScriptName, 'Oqtane.Scripts.', ''), '.sql', '') As MigrationId,
ProductVersion = '5.0.4', ProductVersion = '5.0.4',

View File

@ -11,7 +11,7 @@ IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.SchemaVersion
) )
END END
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion) INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion)
VALUES ('Tenant.01.00.00.00', '5.0.0', SYSDATETIME(), '{{Version}}') VALUES ('Tenant.01.00.00.00', '5.0.4', SYSDATETIME(), '{{Version}}')
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion) INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion)
SELECT REPLACE(REPLACE(ScriptName, 'Oqtane.Scripts.', ''), '.sql', '') As MigrationId, SELECT REPLACE(REPLACE(ScriptName, 'Oqtane.Scripts.', ''), '.sql', '') As MigrationId,
ProductVersion = '5.0.4', ProductVersion = '5.0.4',