364 lines
18 KiB
C#
364 lines
18 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace AMREZ.EOP.Infrastructures.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddLocationCode : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "provinces",
|
|
schema: "master",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Code = table.Column<string>(type: "character varying(2)", maxLength: 2, nullable: false),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
|
|
created_by = table.Column<string>(type: "text", nullable: true),
|
|
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
updated_by = table.Column<string>(type: "text", nullable: true),
|
|
is_deleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
|
|
Scope = table.Column<string>(type: "text", nullable: false, defaultValue: "global"),
|
|
Name = table.Column<string>(type: "text", nullable: false),
|
|
NameI18n = table.Column<string>(type: "jsonb", nullable: true),
|
|
OverridesGlobalId = table.Column<Guid>(type: "uuid", nullable: true),
|
|
IsActive = table.Column<bool>(type: "boolean", nullable: false, defaultValue: true),
|
|
IsSystem = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
|
|
Meta = table.Column<string>(type: "jsonb", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_provinces", x => x.Id);
|
|
table.UniqueConstraint("AK_provinces_tenant_id_Id", x => new { x.tenant_id, x.Id });
|
|
table.CheckConstraint("ck_provinces_tenant_not_null", "tenant_id is not null");
|
|
table.CheckConstraint("ck_provinces_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "districts",
|
|
schema: "master",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Code = table.Column<string>(type: "character varying(4)", maxLength: 4, nullable: false),
|
|
ProvinceId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
|
|
created_by = table.Column<string>(type: "text", nullable: true),
|
|
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
updated_by = table.Column<string>(type: "text", nullable: true),
|
|
is_deleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
|
|
Scope = table.Column<string>(type: "text", nullable: false, defaultValue: "global"),
|
|
Name = table.Column<string>(type: "text", nullable: false),
|
|
NameI18n = table.Column<string>(type: "jsonb", nullable: true),
|
|
OverridesGlobalId = table.Column<Guid>(type: "uuid", nullable: true),
|
|
IsActive = table.Column<bool>(type: "boolean", nullable: false, defaultValue: true),
|
|
IsSystem = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
|
|
Meta = table.Column<string>(type: "jsonb", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_districts", x => x.Id);
|
|
table.UniqueConstraint("AK_districts_tenant_id_Id", x => new { x.tenant_id, x.Id });
|
|
table.CheckConstraint("ck_districts_tenant_not_null", "tenant_id is not null");
|
|
table.CheckConstraint("ck_districts_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
|
|
table.ForeignKey(
|
|
name: "FK_districts_provinces_tenant_id_ProvinceId",
|
|
columns: x => new { x.tenant_id, x.ProvinceId },
|
|
principalSchema: "master",
|
|
principalTable: "provinces",
|
|
principalColumns: new[] { "tenant_id", "Id" },
|
|
onDelete: ReferentialAction.Restrict);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "province_blocks",
|
|
schema: "master",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
|
|
created_by = table.Column<string>(type: "text", nullable: true),
|
|
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
updated_by = table.Column<string>(type: "text", nullable: true),
|
|
is_deleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
|
|
GlobalId = table.Column<Guid>(type: "uuid", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_province_blocks", x => x.Id);
|
|
table.CheckConstraint("ck_province_blocks_tenant_not_null", "tenant_id is not null");
|
|
table.CheckConstraint("ck_province_blocks_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
|
|
table.ForeignKey(
|
|
name: "FK_province_blocks_provinces_GlobalId",
|
|
column: x => x.GlobalId,
|
|
principalSchema: "master",
|
|
principalTable: "provinces",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "district_blocks",
|
|
schema: "master",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
|
|
created_by = table.Column<string>(type: "text", nullable: true),
|
|
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
updated_by = table.Column<string>(type: "text", nullable: true),
|
|
is_deleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
|
|
GlobalId = table.Column<Guid>(type: "uuid", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_district_blocks", x => x.Id);
|
|
table.CheckConstraint("ck_district_blocks_tenant_not_null", "tenant_id is not null");
|
|
table.CheckConstraint("ck_district_blocks_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
|
|
table.ForeignKey(
|
|
name: "FK_district_blocks_districts_GlobalId",
|
|
column: x => x.GlobalId,
|
|
principalSchema: "master",
|
|
principalTable: "districts",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "subdistricts",
|
|
schema: "master",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Code = table.Column<string>(type: "character varying(6)", maxLength: 6, nullable: false),
|
|
Postcode = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: true),
|
|
DistrictId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
|
|
created_by = table.Column<string>(type: "text", nullable: true),
|
|
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
updated_by = table.Column<string>(type: "text", nullable: true),
|
|
is_deleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
|
|
Scope = table.Column<string>(type: "text", nullable: false, defaultValue: "global"),
|
|
Name = table.Column<string>(type: "text", nullable: false),
|
|
NameI18n = table.Column<string>(type: "jsonb", nullable: true),
|
|
OverridesGlobalId = table.Column<Guid>(type: "uuid", nullable: true),
|
|
IsActive = table.Column<bool>(type: "boolean", nullable: false, defaultValue: true),
|
|
IsSystem = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
|
|
Meta = table.Column<string>(type: "jsonb", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_subdistricts", x => x.Id);
|
|
table.UniqueConstraint("AK_subdistricts_tenant_id_Id", x => new { x.tenant_id, x.Id });
|
|
table.CheckConstraint("ck_subdistricts_tenant_not_null", "tenant_id is not null");
|
|
table.CheckConstraint("ck_subdistricts_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
|
|
table.ForeignKey(
|
|
name: "FK_subdistricts_districts_tenant_id_DistrictId",
|
|
columns: x => new { x.tenant_id, x.DistrictId },
|
|
principalSchema: "master",
|
|
principalTable: "districts",
|
|
principalColumns: new[] { "tenant_id", "Id" },
|
|
onDelete: ReferentialAction.Restrict);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "subdistrict_blocks",
|
|
schema: "master",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
|
|
created_by = table.Column<string>(type: "text", nullable: true),
|
|
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
updated_by = table.Column<string>(type: "text", nullable: true),
|
|
is_deleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
|
|
GlobalId = table.Column<Guid>(type: "uuid", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_subdistrict_blocks", x => x.Id);
|
|
table.CheckConstraint("ck_subdistrict_blocks_tenant_not_null", "tenant_id is not null");
|
|
table.CheckConstraint("ck_subdistrict_blocks_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
|
|
table.ForeignKey(
|
|
name: "FK_subdistrict_blocks_subdistricts_GlobalId",
|
|
column: x => x.GlobalId,
|
|
principalSchema: "master",
|
|
principalTable: "subdistricts",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_district_blocks_GlobalId",
|
|
schema: "master",
|
|
table: "district_blocks",
|
|
column: "GlobalId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_district_blocks_tenant_id",
|
|
schema: "master",
|
|
table: "district_blocks",
|
|
column: "tenant_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_district_blocks_tenant_id_GlobalId",
|
|
schema: "master",
|
|
table: "district_blocks",
|
|
columns: new[] { "tenant_id", "GlobalId" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_districts_Code",
|
|
schema: "master",
|
|
table: "districts",
|
|
column: "Code");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_districts_Scope_tenant_id_Code",
|
|
schema: "master",
|
|
table: "districts",
|
|
columns: new[] { "Scope", "tenant_id", "Code" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_districts_tenant_id",
|
|
schema: "master",
|
|
table: "districts",
|
|
column: "tenant_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_districts_tenant_id_ProvinceId",
|
|
schema: "master",
|
|
table: "districts",
|
|
columns: new[] { "tenant_id", "ProvinceId" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_province_blocks_GlobalId",
|
|
schema: "master",
|
|
table: "province_blocks",
|
|
column: "GlobalId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_province_blocks_tenant_id",
|
|
schema: "master",
|
|
table: "province_blocks",
|
|
column: "tenant_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_province_blocks_tenant_id_GlobalId",
|
|
schema: "master",
|
|
table: "province_blocks",
|
|
columns: new[] { "tenant_id", "GlobalId" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_provinces_Code",
|
|
schema: "master",
|
|
table: "provinces",
|
|
column: "Code");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_provinces_Scope_tenant_id_Code",
|
|
schema: "master",
|
|
table: "provinces",
|
|
columns: new[] { "Scope", "tenant_id", "Code" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_provinces_tenant_id",
|
|
schema: "master",
|
|
table: "provinces",
|
|
column: "tenant_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_subdistrict_blocks_GlobalId",
|
|
schema: "master",
|
|
table: "subdistrict_blocks",
|
|
column: "GlobalId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_subdistrict_blocks_tenant_id",
|
|
schema: "master",
|
|
table: "subdistrict_blocks",
|
|
column: "tenant_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_subdistrict_blocks_tenant_id_GlobalId",
|
|
schema: "master",
|
|
table: "subdistrict_blocks",
|
|
columns: new[] { "tenant_id", "GlobalId" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_subdistricts_Code",
|
|
schema: "master",
|
|
table: "subdistricts",
|
|
column: "Code");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_subdistricts_Postcode",
|
|
schema: "master",
|
|
table: "subdistricts",
|
|
column: "Postcode");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_subdistricts_Scope_tenant_id_Code",
|
|
schema: "master",
|
|
table: "subdistricts",
|
|
columns: new[] { "Scope", "tenant_id", "Code" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_subdistricts_tenant_id",
|
|
schema: "master",
|
|
table: "subdistricts",
|
|
column: "tenant_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_subdistricts_tenant_id_DistrictId",
|
|
schema: "master",
|
|
table: "subdistricts",
|
|
columns: new[] { "tenant_id", "DistrictId" });
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "district_blocks",
|
|
schema: "master");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "province_blocks",
|
|
schema: "master");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "subdistrict_blocks",
|
|
schema: "master");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "subdistricts",
|
|
schema: "master");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "districts",
|
|
schema: "master");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "provinces",
|
|
schema: "master");
|
|
}
|
|
}
|
|
}
|