Add support for Sqlite - Installation path tested but AddSite not supported yet
This commit is contained in:
@ -12,7 +12,7 @@ using Oqtane.Enums;
|
||||
|
||||
namespace Oqtane.Modules.HtmlText.Manager
|
||||
{
|
||||
public class HtmlTextManager : IMigratable, IPortable
|
||||
public class HtmlTextManager : MigratableModuleBase, IInstallable, IPortable
|
||||
{
|
||||
private readonly IHtmlTextRepository _htmlText;
|
||||
private readonly ISqlRepository _sql;
|
||||
@ -23,35 +23,6 @@ namespace Oqtane.Modules.HtmlText.Manager
|
||||
_sql = sql;
|
||||
}
|
||||
|
||||
public bool Migrate(Tenant tenant, MigrationType migrationType)
|
||||
{
|
||||
var result = true;
|
||||
|
||||
var dbConfig = new DbConfig(null, null) {ConnectionString = tenant.DBConnectionString};
|
||||
using (var db = new HtmlTextContext(dbConfig, null))
|
||||
{
|
||||
try
|
||||
{
|
||||
var migrator = db.GetService<IMigrator>();
|
||||
if (migrationType == MigrationType.Down)
|
||||
{
|
||||
migrator.Migrate(Migration.InitialDatabase);
|
||||
}
|
||||
else
|
||||
{
|
||||
migrator.Migrate();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
result = false;
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public string ExportModule(Module module)
|
||||
{
|
||||
string content = "";
|
||||
@ -80,5 +51,17 @@ namespace Oqtane.Modules.HtmlText.Manager
|
||||
_htmlText.AddHtmlText(htmlText);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Install(Tenant tenant, string version)
|
||||
{
|
||||
var dbConfig = new DbConfig(null, null) {ConnectionString = tenant.DBConnectionString, DatabaseType = tenant.DBType};
|
||||
return Migrate(new HtmlTextContext(dbConfig, null), tenant, MigrationType.Up);
|
||||
}
|
||||
|
||||
public bool Uninstall(Tenant tenant)
|
||||
{
|
||||
var dbConfig = new DbConfig(null, null) {ConnectionString = tenant.DBConnectionString, DatabaseType = tenant.DBType};
|
||||
return Migrate(new HtmlTextContext(dbConfig, null), tenant, MigrationType.Down);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
42
Oqtane.Server/Modules/MigratableModuleBase.cs
Normal file
42
Oqtane.Server/Modules/MigratableModuleBase.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Modules.HtmlText.Repository;
|
||||
using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Modules
|
||||
{
|
||||
public class MigratableModuleBase
|
||||
{
|
||||
public bool Migrate(DBContextBase dbContext, Tenant tenant, MigrationType migrationType)
|
||||
{
|
||||
var result = true;
|
||||
|
||||
using (dbContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var migrator = dbContext.GetService<IMigrator>();
|
||||
if (migrationType == MigrationType.Down)
|
||||
{
|
||||
migrator.Migrate(Migration.InitialDatabase);
|
||||
}
|
||||
else
|
||||
{
|
||||
migrator.Migrate();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
result = false;
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user