handle HtmlText module transition from SQL scripts to Migrations in module rather than in core framework
This commit is contained in:
@ -1,16 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Modules.HtmlText.Models;
|
||||
using Oqtane.Modules.HtmlText.Repository;
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Interfaces;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Shared;
|
||||
|
||||
// ReSharper disable ConvertToUsingDeclaration
|
||||
|
||||
@ -21,13 +16,14 @@ namespace Oqtane.Modules.HtmlText.Manager
|
||||
private readonly IHtmlTextRepository _htmlText;
|
||||
private readonly ITenantManager _tenantManager;
|
||||
private readonly IHttpContextAccessor _accessor;
|
||||
private readonly ISqlRepository _sqlRepository;
|
||||
|
||||
|
||||
public HtmlTextManager(IHtmlTextRepository htmlText, ITenantManager tenantManager, IHttpContextAccessor httpContextAccessor)
|
||||
public HtmlTextManager(IHtmlTextRepository htmlText, ITenantManager tenantManager, IHttpContextAccessor httpContextAccessor, ISqlRepository sqlRepository)
|
||||
{
|
||||
_htmlText = htmlText;
|
||||
_tenantManager = tenantManager;
|
||||
_accessor = httpContextAccessor;
|
||||
_sqlRepository = sqlRepository;
|
||||
}
|
||||
|
||||
public string ExportModule(Module module)
|
||||
@ -61,15 +57,16 @@ namespace Oqtane.Modules.HtmlText.Manager
|
||||
|
||||
public bool Install(Tenant tenant, string version)
|
||||
{
|
||||
_tenantManager.SetTenant(tenant.TenantId);
|
||||
|
||||
if (tenant.DBType == Constants.DefaultDBType && version == "1.0.1")
|
||||
{
|
||||
// version 1.0.0 used SQL scripts rather than migrations, so we need to seed the migration history table
|
||||
AddMigrationHistory(_sqlRepository, tenant, "HtmlText.01.00.00.00");
|
||||
}
|
||||
return Migrate(new HtmlTextContext(_tenantManager, _accessor), tenant, MigrationType.Up);
|
||||
}
|
||||
|
||||
public bool Uninstall(Tenant tenant)
|
||||
{
|
||||
_tenantManager.SetTenant(tenant.TenantId);
|
||||
|
||||
return Migrate(new HtmlTextContext(_tenantManager, _accessor), tenant, MigrationType.Down);
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Modules.HtmlText.Repository;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Modules
|
||||
{
|
||||
@ -38,5 +38,13 @@ namespace Oqtane.Modules
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public void AddMigrationHistory(ISqlRepository sqlRepository, Tenant tenant, string MigrationId)
|
||||
{
|
||||
var query = "IF NOT EXISTS(SELECT 1 FROM __EFMigrationsHistory WHERE MigrationId = '" + MigrationId + "') ";
|
||||
query += "INSERT INTO __EFMigrationsHistory(MigrationId, ProductVersion, AppliedDate, AppliedVersion) ";
|
||||
query += "VALUES('" + MigrationId + "', '5.0.0', SYSDATETIME(), '" + Constants.Version + "')";
|
||||
sqlRepository.ExecuteNonQuery(tenant, query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user