PIbd-21_MasenkinMS_SUBD_Rou.../RouteGuide/RouteGuideDatabaseImplement/Migrations/20240407200755_InitialCreate.cs

186 lines
7.8 KiB
C#
Raw Normal View History

2024-04-08 21:05:52 +04:00
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace RouteGuideDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Drivers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FullName = table.Column<string>(type: "text", nullable: false),
Phone = table.Column<string>(type: "text", nullable: false),
Experience = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Drivers", x => x.Id);
});
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),
Street = table.Column<string>(type: "text", nullable: false),
Number = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Stops", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Transport",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
License = table.Column<string>(type: "text", nullable: false),
Type = table.Column<int>(type: "integer", nullable: false),
Capacity = table.Column<int>(type: "integer", nullable: false),
DriverId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Transport", x => x.Id);
table.ForeignKey(
name: "FK_Transport_Drivers_DriverId",
column: x => x.DriverId,
principalTable: "Drivers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Routes",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
TransportId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Routes", x => x.Id);
table.ForeignKey(
name: "FK_Routes_Transport_TransportId",
column: x => x.TransportId,
principalTable: "Transport",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "RouteStops",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
RouteId = table.Column<int>(type: "integer", nullable: false),
StopId = table.Column<int>(type: "integer", nullable: false),
Number = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RouteStops", x => x.Id);
table.ForeignKey(
name: "FK_RouteStops_Routes_RouteId",
column: x => x.RouteId,
principalTable: "Routes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_RouteStops_Stops_StopId",
column: x => x.StopId,
principalTable: "Stops",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Schedules",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
DepartureTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
ArrivalTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Frequency = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
RouteId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Schedules", x => x.Id);
table.ForeignKey(
name: "FK_Schedules_Routes_RouteId",
column: x => x.RouteId,
principalTable: "Routes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Routes_TransportId",
table: "Routes",
column: "TransportId");
migrationBuilder.CreateIndex(
name: "IX_RouteStops_RouteId",
table: "RouteStops",
column: "RouteId");
migrationBuilder.CreateIndex(
name: "IX_RouteStops_StopId",
table: "RouteStops",
column: "StopId");
migrationBuilder.CreateIndex(
name: "IX_Schedules_RouteId",
table: "Schedules",
column: "RouteId");
migrationBuilder.CreateIndex(
name: "IX_Transport_DriverId",
table: "Transport",
column: "DriverId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "RouteStops");
migrationBuilder.DropTable(
name: "Schedules");
migrationBuilder.DropTable(
name: "Stops");
migrationBuilder.DropTable(
name: "Routes");
migrationBuilder.DropTable(
name: "Transport");
migrationBuilder.DropTable(
name: "Drivers");
}
}
}