using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace Server.Migrations { public partial class Main_Infrastructure : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_RefreshToken_AspNetUsers_ApplicationUserId", table: "RefreshToken"); migrationBuilder.RenameColumn( name: "ApplicationUserId", table: "RefreshToken", newName: "UserId"); migrationBuilder.CreateTable( name: "Companies", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false), OwnerId = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Companies", x => x.Id); table.ForeignKey( name: "FK_Companies_AspNetUsers_OwnerId", column: x => x.OwnerId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Countries", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Code = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Countries", x => x.Id); }); migrationBuilder.CreateTable( name: "Routes", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Type = table.Column(type: "text", nullable: false), IntendedDepartureTimeOnlyUtc = table.Column(type: "time without time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Routes", x => x.Id); }); migrationBuilder.CreateTable( name: "Vehicles", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Number = table.Column(type: "text", nullable: false), Type = table.Column(type: "text", nullable: false), Capacity = table.Column(type: "integer", nullable: false), CompanyId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Vehicles", x => x.Id); table.ForeignKey( name: "FK_Vehicles_Companies_CompanyId", column: x => x.CompanyId, principalTable: "Companies", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "States", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false), CountryId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_States", x => x.Id); table.ForeignKey( name: "FK_States_Countries_CountryId", column: x => x.CountryId, principalTable: "Countries", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "VehicleEnrollments", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), VehicleId = table.Column(type: "integer", nullable: false), RouteId = table.Column(type: "integer", nullable: false), DepartureDateOnly = table.Column(type: "date", nullable: false), DelayTimeSpan = table.Column(type: "interval", nullable: false) }, constraints: table => { table.PrimaryKey("PK_VehicleEnrollments", x => x.Id); table.ForeignKey( name: "FK_VehicleEnrollments_Routes_RouteId", column: x => x.RouteId, principalTable: "Routes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_VehicleEnrollments_Vehicles_VehicleId", column: x => x.VehicleId, principalTable: "Vehicles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Cities", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false), StateId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Cities", x => x.Id); table.ForeignKey( name: "FK_Cities_States_StateId", column: x => x.StateId, principalTable: "States", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Tickets", columns: table => new { UserId = table.Column(type: "text", nullable: false), VehicleEnrollmentId = table.Column(type: "integer", nullable: false), PurchaseDateTimeUtc = table.Column(type: "timestamp with time zone", nullable: false), IsReturned = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Tickets", x => new { x.UserId, x.VehicleEnrollmentId }); table.ForeignKey( name: "FK_Tickets_AspNetUsers_UserId", column: x => x.UserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Tickets_VehicleEnrollments_VehicleEnrollmentId", column: x => x.VehicleEnrollmentId, principalTable: "VehicleEnrollments", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Addresses", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false), Latitude = table.Column(type: "double precision", nullable: false), Longitude = table.Column(type: "double precision", nullable: false), CityId = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Addresses", x => x.Id); table.ForeignKey( name: "FK_Addresses_Cities_CityId", column: x => x.CityId, principalTable: "Cities", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "RouteAddresses", columns: table => new { RouteId = table.Column(type: "integer", nullable: false), AddressId = table.Column(type: "integer", nullable: false), Order = table.Column(type: "integer", nullable: false), TimeSpanToNextCity = table.Column(type: "interval", nullable: false), WaitTimeSpan = table.Column(type: "interval", nullable: false), CostToNextCity = table.Column(type: "double precision", nullable: false) }, constraints: table => { table.PrimaryKey("PK_RouteAddresses", x => new { x.RouteId, x.AddressId }); table.ForeignKey( name: "FK_RouteAddresses_Addresses_AddressId", column: x => x.AddressId, principalTable: "Addresses", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_RouteAddresses_Routes_RouteId", column: x => x.RouteId, principalTable: "Routes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Addresses_CityId", table: "Addresses", column: "CityId"); migrationBuilder.CreateIndex( name: "IX_Cities_StateId", table: "Cities", column: "StateId"); migrationBuilder.CreateIndex( name: "IX_Companies_OwnerId", table: "Companies", column: "OwnerId"); migrationBuilder.CreateIndex( name: "IX_RouteAddresses_AddressId", table: "RouteAddresses", column: "AddressId"); migrationBuilder.CreateIndex( name: "IX_States_CountryId", table: "States", column: "CountryId"); migrationBuilder.CreateIndex( name: "IX_Tickets_VehicleEnrollmentId", table: "Tickets", column: "VehicleEnrollmentId"); migrationBuilder.CreateIndex( name: "IX_VehicleEnrollments_RouteId", table: "VehicleEnrollments", column: "RouteId"); migrationBuilder.CreateIndex( name: "IX_VehicleEnrollments_VehicleId", table: "VehicleEnrollments", column: "VehicleId"); migrationBuilder.CreateIndex( name: "IX_Vehicles_CompanyId", table: "Vehicles", column: "CompanyId"); migrationBuilder.AddForeignKey( name: "FK_RefreshToken_AspNetUsers_UserId", table: "RefreshToken", column: "UserId", principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_RefreshToken_AspNetUsers_UserId", table: "RefreshToken"); migrationBuilder.DropTable( name: "RouteAddresses"); migrationBuilder.DropTable( name: "Tickets"); migrationBuilder.DropTable( name: "Addresses"); migrationBuilder.DropTable( name: "VehicleEnrollments"); migrationBuilder.DropTable( name: "Cities"); migrationBuilder.DropTable( name: "Routes"); migrationBuilder.DropTable( name: "Vehicles"); migrationBuilder.DropTable( name: "States"); migrationBuilder.DropTable( name: "Companies"); migrationBuilder.DropTable( name: "Countries"); migrationBuilder.RenameColumn( name: "UserId", table: "RefreshToken", newName: "ApplicationUserId"); migrationBuilder.AddForeignKey( name: "FK_RefreshToken_AspNetUsers_ApplicationUserId", table: "RefreshToken", column: "ApplicationUserId", principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); } } }