258 lines
10 KiB
C#
258 lines
10 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Distribution.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class RideLifecycle : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AddColumn<Guid>(
|
|
name: "FK_DefaultWarehouseId",
|
|
table: "Vehicles",
|
|
type: "char(36)",
|
|
nullable: true,
|
|
collation: "ascii_general_ci");
|
|
|
|
migrationBuilder.AddColumn<DateTime>(
|
|
name: "ActivatedAt",
|
|
table: "DeliveryRuns",
|
|
type: "datetime(6)",
|
|
nullable: true);
|
|
|
|
migrationBuilder.AddColumn<DateTime>(
|
|
name: "ClosedAt",
|
|
table: "DeliveryRuns",
|
|
type: "datetime(6)",
|
|
nullable: true);
|
|
|
|
migrationBuilder.AddColumn<Guid>(
|
|
name: "FK_DriverProfileId",
|
|
table: "DeliveryRuns",
|
|
type: "char(36)",
|
|
nullable: false,
|
|
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
|
|
collation: "ascii_general_ci");
|
|
|
|
migrationBuilder.AddColumn<Guid>(
|
|
name: "FK_SourceWarehouseId",
|
|
table: "DeliveryRuns",
|
|
type: "char(36)",
|
|
nullable: false,
|
|
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
|
|
collation: "ascii_general_ci");
|
|
|
|
migrationBuilder.AddColumn<int>(
|
|
name: "RideType",
|
|
table: "DeliveryRuns",
|
|
type: "int",
|
|
nullable: false,
|
|
defaultValue: 0);
|
|
|
|
migrationBuilder.AddColumn<DateTime>(
|
|
name: "StartedAt",
|
|
table: "DeliveryRuns",
|
|
type: "datetime(6)",
|
|
nullable: true);
|
|
|
|
migrationBuilder.AddColumn<int>(
|
|
name: "Status",
|
|
table: "DeliveryRuns",
|
|
type: "int",
|
|
nullable: false,
|
|
defaultValue: 0);
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "DriverComplianceConfigs",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
EnforceLicenseExpiry = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
|
EnforceMedicalClearance = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
UpdatedBy = table.Column<Guid>(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<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
FK_UserId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
LicenseNumber = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
LicenseExpiry = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
MedicalClearanceExpiry = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
IsActive = table.Column<bool>(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<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
FK_RideId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
TypeCode = table.Column<int>(type: "int", nullable: false),
|
|
Reason = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
RequestedBy = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
|
RequestedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
Status = table.Column<int>(type: "int", nullable: false),
|
|
ApprovedBy = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
|
|
ApprovedAt = table.Column<DateTime>(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);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
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");
|
|
}
|
|
}
|
|
}
|