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 };
ValidateConfiguration();
if (!string.IsNullOrEmpty(_config.GetConnectionString(SettingKeys.ConnectionStringKey)))
{
result.Success = true;
@ -82,6 +80,8 @@ namespace Oqtane.Infrastructure
{
var result = new Installation { Success = false, Message = string.Empty };
ValidateConfiguration();
// get configuration
if (install == null)
{
@ -94,24 +94,10 @@ namespace Oqtane.Infrastructure
IsNewTenant = false
};
// check upgrade status
if (!string.IsNullOrEmpty(install.ConnectionString))
// on upgrade install the associated Nuget package
if (!string.IsNullOrEmpty(install.ConnectionString) && Type.GetType(install.DatabaseType) == null)
{
// if no database type has been specified default to Sql Server
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);
}
}
InstallDatabase(install);
}
var installation = IsInstalled();
@ -216,8 +202,8 @@ namespace Oqtane.Infrastructure
{
//Rename bak extension
var packageFolderName = "Packages";
var webRootPath = _environment.WebRootPath;
var packagesFolder = new DirectoryInfo(Path.Combine(webRootPath, packageFolderName));
var path = _environment.ContentRootPath;
var packagesFolder = new DirectoryInfo(Path.Combine(path, packageFolderName));
// iterate through Nuget packages in source folder
foreach (var package in packagesFolder.GetFiles("*.nupkg.bak"))
@ -329,12 +315,6 @@ namespace Oqtane.Infrastructure
{
result.Message = ex.Message;
}
if (!result.Success)
{
UpdateConnectionString(String.Empty);
UpdateDatabaseType(String.Empty);
}
}
}
else
@ -655,7 +635,7 @@ namespace Oqtane.Infrastructure
private InstallationContext GetInstallationContext()
{
var connectionString = _config.GetConnectionString(SettingKeys.ConnectionStringKey);
var connectionString = NormalizeConnectionString(_config.GetConnectionString(SettingKeys.ConnectionStringKey));
var databaseType = _config.GetSection(SettingKeys.DatabaseSection)[SettingKeys.DatabaseTypeKey];
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,
ProductVersion nvarchar(32) NOT NULL,
AppliedVersion nvarchar(10) NOT NULL,
AppliedDate datetime DEFAULT GETDATE()
AppliedDate datetime2(7) NOT NULL,
AppliedVersion nvarchar(10) NULL
)
END
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedVersion)
VALUES ('Master.01.00.00.00', '5.0.0', '{{Version}}')
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedVersion)
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion)
VALUES ('Master.01.00.00.00', '5.0.0', SYSDATETIME(), '{{Version}}')
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion)
SELECT REPLACE(REPLACE(ScriptName, 'Oqtane.Scripts.', ''), '.sql', '') As MigrationId,
ProductVersion = '5.0.0',
AppliedDate = CONVERT(datetime2(7), Applied),
AppliedVersion = '{{Version}}'
FROM SchemaVersions
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,
ProductVersion nvarchar(32) NOT NULL,
AppliedVersion nvarchar(10) NOT NULL,
AppliedDate datetime DEFAULT GETDATE()
AppliedDate datetime2(7) NOT NULL,
AppliedVersion nvarchar(10) NULL
)
END
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedVersion)
VALUES ('Tenant.01.00.00.00', '5.0.0', '{{Version}}')
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedVersion)
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion)
VALUES ('Tenant.01.00.00.00', '5.0.0', SYSDATETIME(), '{{Version}}')
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion)
SELECT REPLACE(REPLACE(ScriptName, 'Oqtane.Scripts.', ''), '.sql', '') As MigrationId,
ProductVersion = '5.0.0',
AppliedDate = CONVERT(datetime2(7), Applied),
AppliedVersion = '{{Version}}'
FROM SchemaVersions
WHERE ScriptName LIKE 'Oqtane.Scripts.Tenant.01%'
OR ScriptName LIKE 'Oqtane.Scripts.Tenant.02%'
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedVersion)
VALUES ('HtmlText.01.00.00.00', '5.0.0', '{{Version}}')
INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion)
VALUES ('HtmlText.01.00.00.00', '5.0.0', SYSDATETIME(), '{{Version}}')
END