using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace RouteGuideDatabaseImplement.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Drivers", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), FullName = table.Column(type: "text", nullable: false), Phone = table.Column(type: "text", nullable: false), Experience = table.Column(type: "integer", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Drivers", x => x.Id); }); migrationBuilder.CreateTable( name: "Stops", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false), Street = table.Column(type: "text", nullable: false), Number = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Stops", x => x.Id); }); migrationBuilder.CreateTable( name: "Transport", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), License = table.Column(type: "text", nullable: false), Type = table.Column(type: "integer", nullable: false), Capacity = table.Column(type: "integer", nullable: false), DriverId = table.Column(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(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false), TransportId = table.Column(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(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), RouteId = table.Column(type: "integer", nullable: false), StopId = table.Column(type: "integer", nullable: false), Number = table.Column(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(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Date = table.Column(type: "timestamp with time zone", nullable: false), DepartureTime = table.Column(type: "timestamp with time zone", nullable: false), ArrivalTime = table.Column(type: "timestamp with time zone", nullable: false), Frequency = table.Column(type: "timestamp with time zone", nullable: false), RouteId = table.Column(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"); } /// 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"); } } }