Page IsClickable column must be nullable in order to support upgrades, add more defensive logic
This commit is contained in:
parent
bfafffd8cb
commit
8e7b553ca8
@ -17,6 +17,7 @@ using Oqtane.Repository;
|
||||
using Oqtane.Shared;
|
||||
using Oqtane.Enums;
|
||||
using Newtonsoft.Json;
|
||||
using System.Diagnostics;
|
||||
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable ConvertToUsingDeclaration
|
||||
@ -55,16 +56,25 @@ namespace Oqtane.Infrastructure
|
||||
{
|
||||
try
|
||||
{
|
||||
// verify master database contains a Tenant table ( ie. validate schema is properly provisioned )
|
||||
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))
|
||||
{
|
||||
Debug.WriteLine($"Oqtane Error: {installation.Message}");
|
||||
// problem with prior installation
|
||||
install.ConnectionString = "";
|
||||
}
|
||||
|
@ -5,7 +5,9 @@ using Newtonsoft.Json;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Shared;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
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)
|
||||
{
|
||||
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
|
||||
|
||||
//var pageTemplates = new List<PageTemplate>();
|
||||
//
|
||||
//pageTemplates.Add(new PageTemplate
|
||||
//{
|
||||
// Name = "Test",
|
||||
// Parent = "",
|
||||
// Order = 1,
|
||||
// Path = "test",
|
||||
// Icon = Icons.Badge,
|
||||
// IsNavigation = true,
|
||||
// IsPersonalizable = false,
|
||||
// EditMode = false,
|
||||
// IsClickable = true,
|
||||
// PagePermissions = new List<Permission>
|
||||
// {
|
||||
// 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)
|
||||
@ -100,19 +113,28 @@ namespace Oqtane.Infrastructure
|
||||
{
|
||||
Directory.Delete(internalTemplatePath, true);
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
// error deleting directory
|
||||
Debug.WriteLine($"Oqtane Error: Error In 2.0.2 Upgrade Logic - {ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// initialize SiteGuid
|
||||
var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
|
||||
foreach (Site site in sites.GetSites().ToList())
|
||||
try
|
||||
{
|
||||
site.SiteGuid = System.Guid.NewGuid().ToString();
|
||||
sites.UpdateSite(site);
|
||||
var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,9 +45,9 @@ namespace Oqtane.Migrations.EntityBuilders
|
||||
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)
|
||||
@ -85,7 +85,7 @@ namespace Oqtane.Migrations.EntityBuilders
|
||||
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);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ using Oqtane.Repository;
|
||||
namespace Oqtane.Migrations.Tenant
|
||||
{
|
||||
[DbContext(typeof(TenantDBContext))]
|
||||
[Migration("Tenant.02.01.01.00")]
|
||||
[Migration("Tenant.02.02.00.01")]
|
||||
public class AddPageIsClickable : MultiDatabaseMigration
|
||||
{
|
||||
public AddPageIsClickable(IDatabase database) : base(database)
|
||||
@ -18,7 +18,7 @@ namespace Oqtane.Migrations.Tenant
|
||||
{
|
||||
var pageEntityBuilder = new PageEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
|
||||
pageEntityBuilder.AddBooleanColumn("IsClickable");
|
||||
pageEntityBuilder.AddBooleanColumn("IsClickable", true);
|
||||
pageEntityBuilder.UpdateColumn("IsClickable", "1");
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.SchemaVersion
|
||||
)
|
||||
END
|
||||
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)
|
||||
SELECT REPLACE(REPLACE(ScriptName, 'Oqtane.Scripts.', ''), '.sql', '') As MigrationId,
|
||||
ProductVersion = '5.0.4',
|
||||
|
@ -11,7 +11,7 @@ IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.SchemaVersion
|
||||
)
|
||||
END
|
||||
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)
|
||||
SELECT REPLACE(REPLACE(ScriptName, 'Oqtane.Scripts.', ''), '.sql', '') As MigrationId,
|
||||
ProductVersion = '5.0.4',
|
||||
|
Reference in New Issue
Block a user