diff --git a/Oqtane.Server/Infrastructure/DatabaseManager.cs b/Oqtane.Server/Infrastructure/DatabaseManager.cs index a7030c6a..1eca23e9 100644 --- a/Oqtane.Server/Infrastructure/DatabaseManager.cs +++ b/Oqtane.Server/Infrastructure/DatabaseManager.cs @@ -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; diff --git a/Oqtane.Server/Scripts/MigrateMaster.sql b/Oqtane.Server/Scripts/MigrateMaster.sql index 4ce2fa9e..00952eee 100644 --- a/Oqtane.Server/Scripts/MigrateMaster.sql +++ b/Oqtane.Server/Scripts/MigrateMaster.sql @@ -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%' diff --git a/Oqtane.Server/Scripts/MigrateTenant.sql b/Oqtane.Server/Scripts/MigrateTenant.sql index b83d27e0..408172ca 100644 --- a/Oqtane.Server/Scripts/MigrateTenant.sql +++ b/Oqtane.Server/Scripts/MigrateTenant.sql @@ -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 \ No newline at end of file