Move Migrations into Master and Tenant folders so its clear what type of Migration is being applied
This commit is contained in:
64
Oqtane.Server/Migrations/Master/01000000_InitializeMaster.cs
Normal file
64
Oqtane.Server/Migrations/Master/01000000_InitializeMaster.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Databases.Interfaces;
|
||||
using Oqtane.Migrations.EntityBuilders;
|
||||
using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Migrations.Master
|
||||
{
|
||||
[DbContext(typeof(MasterDBContext))]
|
||||
[Migration("Master.01.00.00.00")]
|
||||
public class InitializeMaster : MultiDatabaseMigration
|
||||
{
|
||||
public InitializeMaster(IDatabase database) : base(database)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
//Create Tenant table
|
||||
var tenantEntityBuilder = new TenantEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
tenantEntityBuilder.Create();
|
||||
|
||||
//Create Alias table
|
||||
var aliasEntityBuilder = new AliasEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
aliasEntityBuilder.Create();
|
||||
|
||||
//Create ModuleDefinitions Table
|
||||
var moduleDefinitionsEntityBuilder = new ModuleDefinitionsEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
moduleDefinitionsEntityBuilder.Create();
|
||||
|
||||
//Create Job Table
|
||||
var jobEntityBuilder = new JobEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
jobEntityBuilder.Create();
|
||||
|
||||
//Create JobLog Table
|
||||
var jobLogEntityBuilder = new JobLogEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
jobLogEntityBuilder.Create();
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
//Drop Alias table
|
||||
var aliasEntityBuilder = new AliasEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
aliasEntityBuilder.Drop();
|
||||
|
||||
//Drop JobLog Table
|
||||
var jobLogEntityBuilder = new JobLogEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
jobLogEntityBuilder.Drop();
|
||||
|
||||
//Drop Tenant table
|
||||
var tenantEntityBuilder = new TenantEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
tenantEntityBuilder.Drop();
|
||||
|
||||
//Drop ModuleDefinitions Table
|
||||
var moduleDefinitionsEntityBuilder = new ModuleDefinitionsEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
moduleDefinitionsEntityBuilder.Drop();
|
||||
|
||||
//Drop Job Table
|
||||
var jobEntityBuilder = new JobEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
jobEntityBuilder.Drop();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Databases.Interfaces;
|
||||
using Oqtane.Migrations.EntityBuilders;
|
||||
using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Migrations.Master
|
||||
{
|
||||
[DbContext(typeof(MasterDBContext))]
|
||||
[Migration("Master.01.00.01.00")]
|
||||
public class AddAdditionalIndexesInMaster : MultiDatabaseMigration
|
||||
{
|
||||
public AddAdditionalIndexesInMaster(IDatabase database) : base(database)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
//Update Tenant table
|
||||
var tenantEntityBuilder = new TenantEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
tenantEntityBuilder.AddIndex("IX_Tenant", "Name");
|
||||
|
||||
//Update Alias table
|
||||
var aliasEntityBuilder = new AliasEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
aliasEntityBuilder.AddIndex("IX_Alias", "Name");
|
||||
|
||||
//Update ModuleDefinitions Table
|
||||
var moduleDefinitionsEntityBuilder = new ModuleDefinitionsEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
moduleDefinitionsEntityBuilder.AddIndex("IX_ModuleDefinition", "ModuleDefinitionName");
|
||||
|
||||
//Update Job Table
|
||||
var jobEntityBuilder = new JobEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
jobEntityBuilder.AddIndex("IX_Job", "JobType");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
//Update Tenant table
|
||||
var tenantEntityBuilder = new TenantEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
tenantEntityBuilder.DropIndex("IX_Tenant");
|
||||
|
||||
//Update Alias table
|
||||
var aliasEntityBuilder = new AliasEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
aliasEntityBuilder.DropIndex("IX_Alias");
|
||||
|
||||
//Update ModuleDefinitions Table
|
||||
var moduleDefinitionsEntityBuilder = new ModuleDefinitionsEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
moduleDefinitionsEntityBuilder.DropIndex("IX_ModuleDefinition");
|
||||
|
||||
//Update Job Table
|
||||
var jobEntityBuilder = new JobEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
jobEntityBuilder.DropIndex("IX_Job");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Databases.Interfaces;
|
||||
using Oqtane.Migrations.EntityBuilders;
|
||||
using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Migrations.Master
|
||||
{
|
||||
[DbContext(typeof(MasterDBContext))]
|
||||
[Migration("Master.02.01.00.00")]
|
||||
public class AddIndexesForForeignKeyInMaster : MultiDatabaseMigration
|
||||
{
|
||||
public AddIndexesForForeignKeyInMaster(IDatabase database) : base(database)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
//Update JobLog table
|
||||
var jobLogEntityBuilder = new JobLogEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
jobLogEntityBuilder.AddIndex("IX_JobLog_JobId", "JobId");
|
||||
|
||||
//Update Alias table
|
||||
var aliasEntityBuilder = new AliasEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
aliasEntityBuilder.AddIndex("IX_Alias_TenantId", "TenantId");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
//Update JobLog table
|
||||
var jobLogEntityBuilder = new JobLogEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
jobLogEntityBuilder.DropIndex("IX_JobLog_JobId");
|
||||
|
||||
//Update Alias table
|
||||
var aliasEntityBuilder = new AliasEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
aliasEntityBuilder.DropIndex("IX_Alias_TenantId");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Databases.Interfaces;
|
||||
using Oqtane.Migrations.EntityBuilders;
|
||||
using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Migrations.Master
|
||||
{
|
||||
[DbContext(typeof(MasterDBContext))]
|
||||
[Migration("Master.02.01.00.01")]
|
||||
public class AddDatabaseTypeColumnToTenant : MultiDatabaseMigration
|
||||
{
|
||||
public AddDatabaseTypeColumnToTenant(IDatabase database) : base(database)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
//Add Column to Site table
|
||||
var tenantEntityBuilder = new TenantEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
tenantEntityBuilder.AddStringColumn("DBType", 200, true);
|
||||
|
||||
//Update new column if SqlServer (Other Databases will not have any records yet)
|
||||
if (ActiveDatabase.Name == "SqlServer")
|
||||
{
|
||||
tenantEntityBuilder.UpdateColumn("DBType", $"'{ActiveDatabase.TypeName}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user