using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace JobsMedical.Web.Migrations
{
///
public partial class AddDistricts : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn(
name: "DistrictId",
table: "Facilities",
type: "integer",
nullable: true);
migrationBuilder.CreateTable(
name: "Districts",
columns: table => new
{
Id = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
CityId = table.Column(type: "integer", nullable: false),
Name = table.Column(type: "character varying(120)", maxLength: 120, nullable: false),
IsActive = table.Column(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);
}
///
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");
}
}
}