Added suuport to inject an IOqtaneDatabase in EntityBuilders to allow each Database to control certain Migration behaviors. Also updated Installer to dynamically build Database Configuration section
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Repository;
|
||||
@ -8,6 +9,8 @@ using System.Net;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Interfaces;
|
||||
|
||||
// ReSharper disable ConvertToUsingDeclaration
|
||||
|
||||
namespace Oqtane.Modules.HtmlText.Manager
|
||||
@ -15,12 +18,12 @@ namespace Oqtane.Modules.HtmlText.Manager
|
||||
public class HtmlTextManager : MigratableModuleBase, IInstallable, IPortable
|
||||
{
|
||||
private readonly IHtmlTextRepository _htmlText;
|
||||
private readonly ISqlRepository _sql;
|
||||
private readonly IEnumerable<IOqtaneDatabase> _databases;
|
||||
|
||||
public HtmlTextManager(IHtmlTextRepository htmlText, ISqlRepository sql)
|
||||
public HtmlTextManager(IHtmlTextRepository htmlText, IEnumerable<IOqtaneDatabase> databases)
|
||||
{
|
||||
_htmlText = htmlText;
|
||||
_sql = sql;
|
||||
_databases = databases;
|
||||
}
|
||||
|
||||
public string ExportModule(Module module)
|
||||
@ -54,13 +57,13 @@ namespace Oqtane.Modules.HtmlText.Manager
|
||||
|
||||
public bool Install(Tenant tenant, string version)
|
||||
{
|
||||
var dbConfig = new DbConfig(null, null) {ConnectionString = tenant.DBConnectionString, DatabaseType = tenant.DBType};
|
||||
var dbConfig = new DbConfig(null, null, _databases) {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};
|
||||
var dbConfig = new DbConfig(null, null, _databases) {ConnectionString = tenant.DBConnectionString, DatabaseType = tenant.DBType};
|
||||
return Migrate(new HtmlTextContext(dbConfig, null), tenant, MigrationType.Down);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Interfaces;
|
||||
using Oqtane.Migrations;
|
||||
using Oqtane.Modules.HtmlText.Migrations.EntityBuilders;
|
||||
using Oqtane.Modules.HtmlText.Repository;
|
||||
|
||||
@ -7,19 +10,23 @@ namespace Oqtane.Modules.HtmlText.Migrations
|
||||
{
|
||||
[DbContext(typeof(HtmlTextContext))]
|
||||
[Migration("HtmlText.01.00.00.00")]
|
||||
public class InitializeModule : Migration
|
||||
public class InitializeModule : MultiDatabaseMigration
|
||||
{
|
||||
public InitializeModule(IEnumerable<IOqtaneDatabase> databases) : base(databases)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
//Create HtmlText table
|
||||
var entityBuilder = new HtmlTextEntityBuilder(migrationBuilder);
|
||||
var entityBuilder = new HtmlTextEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
entityBuilder.Create();
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
//Drop HtmlText table
|
||||
var entityBuilder = new HtmlTextEntityBuilder(migrationBuilder);
|
||||
var entityBuilder = new HtmlTextEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
entityBuilder.Drop();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations.Operations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders;
|
||||
using Oqtane.Interfaces;
|
||||
using Oqtane.Migrations;
|
||||
using Oqtane.Migrations.EntityBuilders;
|
||||
using Oqtane.Migrations.Extensions;
|
||||
@ -16,7 +17,7 @@ namespace Oqtane.Modules.HtmlText.Migrations.EntityBuilders
|
||||
private readonly PrimaryKey<HtmlTextEntityBuilder> _primaryKey = new("PK_HtmlText", x => x.HtmlTextId);
|
||||
private readonly ForeignKey<HtmlTextEntityBuilder> _moduleForeignKey = new("FK_HtmlText_Module", x => x.ModuleId, "Module", "ModuleId", ReferentialAction.Cascade);
|
||||
|
||||
public HtmlTextEntityBuilder(MigrationBuilder migrationBuilder) : base(migrationBuilder)
|
||||
public HtmlTextEntityBuilder(MigrationBuilder migrationBuilder, IOqtaneDatabase database) : base(migrationBuilder, database)
|
||||
{
|
||||
EntityTableName = _entityTableName;
|
||||
PrimaryKey = _primaryKey;
|
||||
@ -25,7 +26,7 @@ namespace Oqtane.Modules.HtmlText.Migrations.EntityBuilders
|
||||
|
||||
protected override HtmlTextEntityBuilder BuildTable(ColumnsBuilder table)
|
||||
{
|
||||
HtmlTextId = table.AddAutoIncrementColumn("HtmlTextId");
|
||||
HtmlTextId = ActiveDatabase.AddAutoIncrementColumn(table,"HtmlTextId");
|
||||
ModuleId = table.AddIntegerColumn("ModuleId");
|
||||
Content = table.AddMaxStringColumn("Content");
|
||||
|
||||
|
@ -1,18 +1,21 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Modules.HtmlText.Models;
|
||||
using Oqtane.Repository;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Oqtane.Interfaces;
|
||||
using Oqtane.Repository.Databases.Interfaces;
|
||||
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
|
||||
namespace Oqtane.Modules.HtmlText.Repository
|
||||
{
|
||||
public class HtmlTextContext : DBContextBase, IService
|
||||
public class HtmlTextContext : DBContextBase, IService, IMultiDatabase
|
||||
{
|
||||
public virtual DbSet<HtmlTextInfo> HtmlText { get; set; }
|
||||
|
||||
public HtmlTextContext(IDbConfig dbConfig, ITenantResolver tenantResolver) : base(dbConfig, tenantResolver)
|
||||
{
|
||||
// ContextBase handles multi-tenant database connections
|
||||
}
|
||||
|
||||
public virtual DbSet<HtmlTextInfo> HtmlText { get; set; }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user