320da0e1c9
Creates RegionAgencyMaps, RegionalBudgets, RegionalTargets, and RegionalTaxRules with their unique indexes and foreign keys, and applies the migration to the shared MySQL database. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
160 lines
7.3 KiB
C#
160 lines
7.3 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Distribution.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddRegionManagement : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "RegionAgencyMaps",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
FK_RegionId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
FK_AgencyUserId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
IsActive = table.Column<bool>(type: "tinyint(1)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_RegionAgencyMaps", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_RegionAgencyMaps_Regions_FK_RegionId",
|
|
column: x => x.FK_RegionId,
|
|
principalTable: "Regions",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_RegionAgencyMaps_Users_FK_AgencyUserId",
|
|
column: x => x.FK_AgencyUserId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "RegionalBudgets",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
FK_RegionId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
Period = table.Column<string>(type: "varchar(255)", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
BudgetAmount = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
IsActive = table.Column<bool>(type: "tinyint(1)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_RegionalBudgets", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_RegionalBudgets_Regions_FK_RegionId",
|
|
column: x => x.FK_RegionId,
|
|
principalTable: "Regions",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "RegionalTargets",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
FK_RegionId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
Period = table.Column<string>(type: "varchar(255)", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
TargetValue = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
IsActive = table.Column<bool>(type: "tinyint(1)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_RegionalTargets", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_RegionalTargets_Regions_FK_RegionId",
|
|
column: x => x.FK_RegionId,
|
|
principalTable: "Regions",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "RegionalTaxRules",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
FK_RegionId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
RuleConfig = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
IsActive = table.Column<bool>(type: "tinyint(1)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_RegionalTaxRules", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_RegionalTaxRules_Regions_FK_RegionId",
|
|
column: x => x.FK_RegionId,
|
|
principalTable: "Regions",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_RegionAgencyMaps_FK_AgencyUserId",
|
|
table: "RegionAgencyMaps",
|
|
column: "FK_AgencyUserId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_RegionAgencyMaps_FK_RegionId_FK_AgencyUserId",
|
|
table: "RegionAgencyMaps",
|
|
columns: new[] { "FK_RegionId", "FK_AgencyUserId" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_RegionalBudgets_FK_RegionId_Period",
|
|
table: "RegionalBudgets",
|
|
columns: new[] { "FK_RegionId", "Period" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_RegionalTargets_FK_RegionId_Period",
|
|
table: "RegionalTargets",
|
|
columns: new[] { "FK_RegionId", "Period" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_RegionalTaxRules_FK_RegionId",
|
|
table: "RegionalTaxRules",
|
|
column: "FK_RegionId",
|
|
unique: true);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "RegionAgencyMaps");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "RegionalBudgets");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "RegionalTargets");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "RegionalTaxRules");
|
|
}
|
|
}
|
|
}
|