151 lines
6.7 KiB
C#
151 lines
6.7 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
|
|
#nullable disable
|
|
|
|
namespace LogisticsApp.Server.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class fix : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "Orders",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
ClientName = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
|
|
OrderCost = table.Column<decimal>(type: "numeric(18,2)", nullable: false),
|
|
OrderDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
Status = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
|
Address = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
|
|
Description = table.Column<string>(type: "text", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Orders", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Users",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
Username = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
PasswordHash = table.Column<string>(type: "text", nullable: false),
|
|
Role = table.Column<string>(type: "text", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Users", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Vehicles",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
DriverName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
VehicleType = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
LicensePlate = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Vehicles", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "WaybillEntries",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
VehicleId = table.Column<int>(type: "integer", nullable: false),
|
|
OrderId = table.Column<int>(type: "integer", nullable: false),
|
|
StartTime = table.Column<string>(type: "character varying(5)", maxLength: 5, nullable: false),
|
|
EndTime = table.Column<string>(type: "character varying(5)", maxLength: 5, nullable: false),
|
|
Date = table.Column<DateOnly>(type: "date", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_WaybillEntries", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_WaybillEntries_Orders_OrderId",
|
|
column: x => x.OrderId,
|
|
principalTable: "Orders",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_WaybillEntries_Vehicles_VehicleId",
|
|
column: x => x.VehicleId,
|
|
principalTable: "Vehicles",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Orders_ClientName",
|
|
table: "Orders",
|
|
column: "ClientName");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Orders_OrderDate",
|
|
table: "Orders",
|
|
column: "OrderDate");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Orders_Status",
|
|
table: "Orders",
|
|
column: "Status");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Users_Username",
|
|
table: "Users",
|
|
column: "Username",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Vehicles_LicensePlate",
|
|
table: "Vehicles",
|
|
column: "LicensePlate");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_WaybillEntries_OrderId",
|
|
table: "WaybillEntries",
|
|
column: "OrderId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_WaybillEntries_VehicleId_Date",
|
|
table: "WaybillEntries",
|
|
columns: new[] { "VehicleId", "Date" });
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "Users");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "WaybillEntries");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Orders");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Vehicles");
|
|
}
|
|
}
|
|
}
|