DB/TransportGuideDatabaseImplements/Migrations/20230504163433_InitialCreate.cs

122 lines
4.9 KiB
C#

using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace TransportGuideDatabaseImplements.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Stops",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Stops", x => x.Id);
});
migrationBuilder.CreateTable(
name: "TransportTypes",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Price = table.Column<double>(type: "double precision", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TransportTypes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Routes",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
TransportTypeId = table.Column<int>(type: "integer", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
IP = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Routes", x => x.Id);
table.ForeignKey(
name: "FK_Routes_TransportTypes_TransportTypeId",
column: x => x.TransportTypeId,
principalTable: "TransportTypes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "StopRoutes",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
StopId = table.Column<int>(type: "integer", nullable: false),
RouteId = table.Column<int>(type: "integer", nullable: false),
Nomer = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_StopRoutes", x => x.Id);
table.ForeignKey(
name: "FK_StopRoutes_Routes_RouteId",
column: x => x.RouteId,
principalTable: "Routes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_StopRoutes_Stops_StopId",
column: x => x.StopId,
principalTable: "Stops",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Routes_TransportTypeId",
table: "Routes",
column: "TransportTypeId");
migrationBuilder.CreateIndex(
name: "IX_StopRoutes_RouteId",
table: "StopRoutes",
column: "RouteId");
migrationBuilder.CreateIndex(
name: "IX_StopRoutes_StopId",
table: "StopRoutes",
column: "StopId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "StopRoutes");
migrationBuilder.DropTable(
name: "Routes");
migrationBuilder.DropTable(
name: "Stops");
migrationBuilder.DropTable(
name: "TransportTypes");
}
}
}