80 lines
2.8 KiB
C#
80 lines
2.8 KiB
C#
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||
|
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||
|
|
|
||
|
|
#nullable disable
|
||
|
|
|
||
|
|
namespace JobsMedical.Web.Migrations
|
||
|
|
{
|
||
|
|
/// <inheritdoc />
|
||
|
|
public partial class AddDistricts : Migration
|
||
|
|
{
|
||
|
|
/// <inheritdoc />
|
||
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||
|
|
{
|
||
|
|
migrationBuilder.AddColumn<int>(
|
||
|
|
name: "DistrictId",
|
||
|
|
table: "Facilities",
|
||
|
|
type: "integer",
|
||
|
|
nullable: true);
|
||
|
|
|
||
|
|
migrationBuilder.CreateTable(
|
||
|
|
name: "Districts",
|
||
|
|
columns: table => new
|
||
|
|
{
|
||
|
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||
|
|
CityId = table.Column<int>(type: "integer", nullable: false),
|
||
|
|
Name = table.Column<string>(type: "character varying(120)", maxLength: 120, nullable: false),
|
||
|
|
IsActive = table.Column<bool>(type: "boolean", nullable: false)
|
||
|
|
},
|
||
|
|
constraints: table =>
|
||
|
|
{
|
||
|
|
table.PrimaryKey("PK_Districts", x => x.Id);
|
||
|
|
table.ForeignKey(
|
||
|
|
name: "FK_Districts_Cities_CityId",
|
||
|
|
column: x => x.CityId,
|
||
|
|
principalTable: "Cities",
|
||
|
|
principalColumn: "Id",
|
||
|
|
onDelete: ReferentialAction.Cascade);
|
||
|
|
});
|
||
|
|
|
||
|
|
migrationBuilder.CreateIndex(
|
||
|
|
name: "IX_Facilities_DistrictId",
|
||
|
|
table: "Facilities",
|
||
|
|
column: "DistrictId");
|
||
|
|
|
||
|
|
migrationBuilder.CreateIndex(
|
||
|
|
name: "IX_Districts_CityId",
|
||
|
|
table: "Districts",
|
||
|
|
column: "CityId");
|
||
|
|
|
||
|
|
migrationBuilder.AddForeignKey(
|
||
|
|
name: "FK_Facilities_Districts_DistrictId",
|
||
|
|
table: "Facilities",
|
||
|
|
column: "DistrictId",
|
||
|
|
principalTable: "Districts",
|
||
|
|
principalColumn: "Id",
|
||
|
|
onDelete: ReferentialAction.SetNull);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <inheritdoc />
|
||
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||
|
|
{
|
||
|
|
migrationBuilder.DropForeignKey(
|
||
|
|
name: "FK_Facilities_Districts_DistrictId",
|
||
|
|
table: "Facilities");
|
||
|
|
|
||
|
|
migrationBuilder.DropTable(
|
||
|
|
name: "Districts");
|
||
|
|
|
||
|
|
migrationBuilder.DropIndex(
|
||
|
|
name: "IX_Facilities_DistrictId",
|
||
|
|
table: "Facilities");
|
||
|
|
|
||
|
|
migrationBuilder.DropColumn(
|
||
|
|
name: "DistrictId",
|
||
|
|
table: "Facilities");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|