Creation of EF Core Migrations - these execute using EF Tools, but are not integrated to run programmatically

This commit is contained in:
Charles Nurse
2021-03-19 17:01:49 -07:00
parent c64f350f36
commit 83e5502111
49 changed files with 2170 additions and 17 deletions

View File

@ -0,0 +1,51 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Oqtane.Migrations.EntityBuilders;
using Oqtane.Repository;
namespace Oqtane.Migrations
{
[DbContext(typeof(TenantDBContext))]
[Migration("Tenant.02.00.00.01")]
public class AddColumnToProfileAndUpdatePage : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
//Add Column to Profile table
var profileEntityBuilder = new ProfileEntityBuilder(migrationBuilder);
profileEntityBuilder.AddStringColumn("Options", 2000, true);
///Update new field
migrationBuilder.Sql(
@"
UPDATE Profile
SET Options = ''
");
//Alter Column in Page table
if (migrationBuilder.ActiveProvider != "Microsoft.EntityFrameworkCore.Sqlite")
{
var pageEntityBuilder = new PageEntityBuilder(migrationBuilder);
pageEntityBuilder.DropIndex("IX_Page");
pageEntityBuilder.AlterStringColumn("Path", 256);
pageEntityBuilder.AddIndex("IX_Page", new [] {"SiteId", "Path", "UserId"}, true);
}
}
protected override void Down(MigrationBuilder migrationBuilder)
{
//Drop Column from Profile table
var profileEntityBuilder = new ProfileEntityBuilder(migrationBuilder);
profileEntityBuilder.DropColumn("Options");
//Alter Column in Page table
if (migrationBuilder.ActiveProvider != "Microsoft.EntityFrameworkCore.Sqlite")
{
var pageEntityBuilder = new PageEntityBuilder(migrationBuilder);
pageEntityBuilder.DropIndex("IX_Page");
pageEntityBuilder.AlterStringColumn("Path", 50);
pageEntityBuilder.AddIndex("IX_Page", new [] {"SiteId", "Path", "UserId"}, true);
}
}
}
}