fixed upgrade logic

This commit is contained in:
Shaun Walker 2021-05-28 16:01:11 -04:00
parent e559a11261
commit 8529a42075
3 changed files with 22 additions and 40 deletions

View File

@ -46,8 +46,6 @@ namespace Oqtane.Infrastructure
{ {
var result = new Installation { Success = false, Message = string.Empty }; var result = new Installation { Success = false, Message = string.Empty };
ValidateConfiguration();
if (!string.IsNullOrEmpty(_config.GetConnectionString(SettingKeys.ConnectionStringKey))) if (!string.IsNullOrEmpty(_config.GetConnectionString(SettingKeys.ConnectionStringKey)))
{ {
result.Success = true; result.Success = true;
@ -82,6 +80,8 @@ namespace Oqtane.Infrastructure
{ {
var result = new Installation { Success = false, Message = string.Empty }; var result = new Installation { Success = false, Message = string.Empty };
ValidateConfiguration();
// get configuration // get configuration
if (install == null) if (install == null)
{ {
@ -94,24 +94,10 @@ namespace Oqtane.Infrastructure
IsNewTenant = false IsNewTenant = false
}; };
// check upgrade status // on upgrade install the associated Nuget package
if (!string.IsNullOrEmpty(install.ConnectionString)) if (!string.IsNullOrEmpty(install.ConnectionString) && Type.GetType(install.DatabaseType) == null)
{ {
// if no database type has been specified default to Sql Server InstallDatabase(install);
if (string.IsNullOrEmpty(install.DatabaseType))
{
install.DatabaseType = Constants.DefaultDBType;
InstallDatabase(install);
UpdateDatabaseType(install.DatabaseType);
}
else
{
// if database type does not exist, install the associated Nuget package
if (Type.GetType(install.DatabaseType) == null)
{
InstallDatabase(install);
}
}
} }
var installation = IsInstalled(); var installation = IsInstalled();
@ -216,8 +202,8 @@ namespace Oqtane.Infrastructure
{ {
//Rename bak extension //Rename bak extension
var packageFolderName = "Packages"; var packageFolderName = "Packages";
var webRootPath = _environment.WebRootPath; var path = _environment.ContentRootPath;
var packagesFolder = new DirectoryInfo(Path.Combine(webRootPath, packageFolderName)); var packagesFolder = new DirectoryInfo(Path.Combine(path, packageFolderName));
// iterate through Nuget packages in source folder // iterate through Nuget packages in source folder
foreach (var package in packagesFolder.GetFiles("*.nupkg.bak")) foreach (var package in packagesFolder.GetFiles("*.nupkg.bak"))
@ -329,12 +315,6 @@ namespace Oqtane.Infrastructure
{ {
result.Message = ex.Message; result.Message = ex.Message;
} }
if (!result.Success)
{
UpdateConnectionString(String.Empty);
UpdateDatabaseType(String.Empty);
}
} }
} }
else else
@ -655,7 +635,7 @@ namespace Oqtane.Infrastructure
private InstallationContext GetInstallationContext() private InstallationContext GetInstallationContext()
{ {
var connectionString = _config.GetConnectionString(SettingKeys.ConnectionStringKey); var connectionString = NormalizeConnectionString(_config.GetConnectionString(SettingKeys.ConnectionStringKey));
var databaseType = _config.GetSection(SettingKeys.DatabaseSection)[SettingKeys.DatabaseTypeKey]; var databaseType = _config.GetSection(SettingKeys.DatabaseSection)[SettingKeys.DatabaseTypeKey];
IDatabase database = null; IDatabase database = null;

View File

@ -6,15 +6,16 @@ IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.SchemaVersion
( (
MigrationId nvarchar(150) NOT NULL CONSTRAINT PK___EFMigrationsHistory PRIMARY KEY, MigrationId nvarchar(150) NOT NULL CONSTRAINT PK___EFMigrationsHistory PRIMARY KEY,
ProductVersion nvarchar(32) NOT NULL, ProductVersion nvarchar(32) NOT NULL,
AppliedVersion nvarchar(10) NOT NULL, AppliedDate datetime2(7) NOT NULL,
AppliedDate datetime DEFAULT GETDATE() AppliedVersion nvarchar(10) NULL
) )
END END
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedVersion) INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion)
VALUES ('Master.01.00.00.00', '5.0.0', '{{Version}}') VALUES ('Master.01.00.00.00', '5.0.0', SYSDATETIME(), '{{Version}}')
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, 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.0', ProductVersion = '5.0.0',
AppliedDate = CONVERT(datetime2(7), Applied),
AppliedVersion = '{{Version}}' AppliedVersion = '{{Version}}'
FROM SchemaVersions FROM SchemaVersions
WHERE ScriptName LIKE 'Oqtane.Scripts.Master.01%' WHERE ScriptName LIKE 'Oqtane.Scripts.Master.01%'

View File

@ -6,19 +6,20 @@ IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.SchemaVersion
( (
MigrationId nvarchar(150) NOT NULL CONSTRAINT PK___EFMigrationsHistory PRIMARY KEY, MigrationId nvarchar(150) NOT NULL CONSTRAINT PK___EFMigrationsHistory PRIMARY KEY,
ProductVersion nvarchar(32) NOT NULL, ProductVersion nvarchar(32) NOT NULL,
AppliedVersion nvarchar(10) NOT NULL, AppliedDate datetime2(7) NOT NULL,
AppliedDate datetime DEFAULT GETDATE() AppliedVersion nvarchar(10) NULL
) )
END END
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedVersion) INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion)
VALUES ('Tenant.01.00.00.00', '5.0.0', '{{Version}}') VALUES ('Tenant.01.00.00.00', '5.0.0', SYSDATETIME(), '{{Version}}')
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, 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.0', ProductVersion = '5.0.0',
AppliedDate = CONVERT(datetime2(7), Applied),
AppliedVersion = '{{Version}}' AppliedVersion = '{{Version}}'
FROM SchemaVersions FROM SchemaVersions
WHERE ScriptName LIKE 'Oqtane.Scripts.Tenant.01%' WHERE ScriptName LIKE 'Oqtane.Scripts.Tenant.01%'
OR ScriptName LIKE 'Oqtane.Scripts.Tenant.02%' OR ScriptName LIKE 'Oqtane.Scripts.Tenant.02%'
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedVersion) INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion)
VALUES ('HtmlText.01.00.00.00', '5.0.0', '{{Version}}') VALUES ('HtmlText.01.00.00.00', '5.0.0', SYSDATETIME(), '{{Version}}')
END END