using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Distribution.Migrations { /// public partial class RideLifecycle : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "FK_DefaultWarehouseId", table: "Vehicles", type: "char(36)", nullable: true, collation: "ascii_general_ci"); migrationBuilder.AddColumn( name: "ActivatedAt", table: "DeliveryRuns", type: "datetime(6)", nullable: true); migrationBuilder.AddColumn( name: "ClosedAt", table: "DeliveryRuns", type: "datetime(6)", nullable: true); migrationBuilder.AddColumn( name: "FK_DriverProfileId", table: "DeliveryRuns", type: "char(36)", nullable: false, defaultValue: new Guid("00000000-0000-0000-0000-000000000000"), collation: "ascii_general_ci"); migrationBuilder.AddColumn( name: "FK_SourceWarehouseId", table: "DeliveryRuns", type: "char(36)", nullable: false, defaultValue: new Guid("00000000-0000-0000-0000-000000000000"), collation: "ascii_general_ci"); migrationBuilder.AddColumn( name: "RideType", table: "DeliveryRuns", type: "int", nullable: false, defaultValue: 0); migrationBuilder.AddColumn( name: "StartedAt", table: "DeliveryRuns", type: "datetime(6)", nullable: true); migrationBuilder.AddColumn( name: "Status", table: "DeliveryRuns", type: "int", nullable: false, defaultValue: 0); migrationBuilder.CreateTable( name: "DriverComplianceConfigs", columns: table => new { Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), EnforceLicenseExpiry = table.Column(type: "tinyint(1)", nullable: false), EnforceMedicalClearance = table.Column(type: "tinyint(1)", nullable: false), UpdatedAt = table.Column(type: "datetime(6)", nullable: false), UpdatedBy = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci") }, constraints: table => { table.PrimaryKey("PK_DriverComplianceConfigs", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "DriverProfiles", columns: table => new { Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_UserId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), LicenseNumber = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), LicenseExpiry = table.Column(type: "datetime(6)", nullable: false), MedicalClearanceExpiry = table.Column(type: "datetime(6)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DriverProfiles", x => x.Id); table.ForeignKey( name: "FK_DriverProfiles_Users_FK_UserId", column: x => x.FK_UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "RideCancelRequests", columns: table => new { Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_RideId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), TypeCode = table.Column(type: "int", nullable: false), Reason = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), RequestedBy = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), RequestedAt = table.Column(type: "datetime(6)", nullable: false), Status = table.Column(type: "int", nullable: false), ApprovedBy = table.Column(type: "char(36)", nullable: true, collation: "ascii_general_ci"), ApprovedAt = table.Column(type: "datetime(6)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_RideCancelRequests", x => x.Id); table.ForeignKey( name: "FK_RideCancelRequests_DeliveryRuns_FK_RideId", column: x => x.FK_RideId, principalTable: "DeliveryRuns", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateIndex( name: "IX_Vehicles_FK_DefaultWarehouseId", table: "Vehicles", column: "FK_DefaultWarehouseId"); migrationBuilder.CreateIndex( name: "IX_DeliveryRuns_FK_DriverProfileId", table: "DeliveryRuns", column: "FK_DriverProfileId"); migrationBuilder.CreateIndex( name: "IX_DeliveryRuns_FK_SourceWarehouseId", table: "DeliveryRuns", column: "FK_SourceWarehouseId"); migrationBuilder.CreateIndex( name: "IX_DriverProfiles_FK_UserId", table: "DriverProfiles", column: "FK_UserId", unique: true); migrationBuilder.CreateIndex( name: "IX_RideCancelRequests_FK_RideId", table: "RideCancelRequests", column: "FK_RideId"); migrationBuilder.AddForeignKey( name: "FK_DeliveryRuns_DriverProfiles_FK_DriverProfileId", table: "DeliveryRuns", column: "FK_DriverProfileId", principalTable: "DriverProfiles", principalColumn: "Id", onDelete: ReferentialAction.Restrict); migrationBuilder.AddForeignKey( name: "FK_DeliveryRuns_Warehouses_FK_SourceWarehouseId", table: "DeliveryRuns", column: "FK_SourceWarehouseId", principalTable: "Warehouses", principalColumn: "Id", onDelete: ReferentialAction.Restrict); migrationBuilder.AddForeignKey( name: "FK_Vehicles_Warehouses_FK_DefaultWarehouseId", table: "Vehicles", column: "FK_DefaultWarehouseId", principalTable: "Warehouses", principalColumn: "Id", onDelete: ReferentialAction.Restrict); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_DeliveryRuns_DriverProfiles_FK_DriverProfileId", table: "DeliveryRuns"); migrationBuilder.DropForeignKey( name: "FK_DeliveryRuns_Warehouses_FK_SourceWarehouseId", table: "DeliveryRuns"); migrationBuilder.DropForeignKey( name: "FK_Vehicles_Warehouses_FK_DefaultWarehouseId", table: "Vehicles"); migrationBuilder.DropTable( name: "DriverComplianceConfigs"); migrationBuilder.DropTable( name: "DriverProfiles"); migrationBuilder.DropTable( name: "RideCancelRequests"); migrationBuilder.DropIndex( name: "IX_Vehicles_FK_DefaultWarehouseId", table: "Vehicles"); migrationBuilder.DropIndex( name: "IX_DeliveryRuns_FK_DriverProfileId", table: "DeliveryRuns"); migrationBuilder.DropIndex( name: "IX_DeliveryRuns_FK_SourceWarehouseId", table: "DeliveryRuns"); migrationBuilder.DropColumn( name: "FK_DefaultWarehouseId", table: "Vehicles"); migrationBuilder.DropColumn( name: "ActivatedAt", table: "DeliveryRuns"); migrationBuilder.DropColumn( name: "ClosedAt", table: "DeliveryRuns"); migrationBuilder.DropColumn( name: "FK_DriverProfileId", table: "DeliveryRuns"); migrationBuilder.DropColumn( name: "FK_SourceWarehouseId", table: "DeliveryRuns"); migrationBuilder.DropColumn( name: "RideType", table: "DeliveryRuns"); migrationBuilder.DropColumn( name: "StartedAt", table: "DeliveryRuns"); migrationBuilder.DropColumn( name: "Status", table: "DeliveryRuns"); } } }