2024-05-05 19:18:53 +04:00
|
|
|
|
using System;
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
|
|
|
|
|
|
|
|
#nullable disable
|
|
|
|
|
|
|
|
|
|
namespace CarShowroomDatabaseStorage.Migrations
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public partial class InitialCreate : Migration
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
|
|
|
{
|
|
|
|
|
migrationBuilder.CreateTable(
|
|
|
|
|
name: "client",
|
|
|
|
|
columns: table => new
|
|
|
|
|
{
|
|
|
|
|
client_id = table.Column<int>(type: "integer", nullable: false)
|
|
|
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
|
|
|
client_name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "empty_string"),
|
2024-05-05 21:21:25 +04:00
|
|
|
|
client_phonenumber = table.Column<string>(type: "character varying(25)", maxLength: 25, nullable: false)
|
2024-05-05 19:18:53 +04:00
|
|
|
|
},
|
|
|
|
|
constraints: table =>
|
|
|
|
|
{
|
|
|
|
|
table.PrimaryKey("PK_client", x => x.client_id);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateTable(
|
|
|
|
|
name: "employee",
|
|
|
|
|
columns: table => new
|
|
|
|
|
{
|
|
|
|
|
employee_id = table.Column<int>(type: "integer", nullable: false)
|
|
|
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
|
|
|
employee_name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "empty_string"),
|
|
|
|
|
employee_email = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
|
|
|
|
|
employee_password = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, defaultValue: "empty_string")
|
|
|
|
|
},
|
|
|
|
|
constraints: table =>
|
|
|
|
|
{
|
|
|
|
|
table.PrimaryKey("PK_employee", x => x.employee_id);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateTable(
|
|
|
|
|
name: "make",
|
|
|
|
|
columns: table => new
|
|
|
|
|
{
|
|
|
|
|
make_id = table.Column<int>(type: "integer", nullable: false)
|
|
|
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
|
|
|
make_name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false)
|
|
|
|
|
},
|
|
|
|
|
constraints: table =>
|
|
|
|
|
{
|
|
|
|
|
table.PrimaryKey("PK_make", x => x.make_id);
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-05 21:21:25 +04:00
|
|
|
|
migrationBuilder.CreateTable(
|
|
|
|
|
name: "service",
|
|
|
|
|
columns: table => new
|
|
|
|
|
{
|
|
|
|
|
service_id = table.Column<int>(type: "integer", nullable: false)
|
|
|
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
|
|
|
service_name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
|
|
|
service_cost = table.Column<int>(type: "integer", nullable: false, defaultValue: -1)
|
|
|
|
|
},
|
|
|
|
|
constraints: table =>
|
|
|
|
|
{
|
|
|
|
|
table.PrimaryKey("PK_service", x => x.service_id);
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-05 19:18:53 +04:00
|
|
|
|
migrationBuilder.CreateTable(
|
|
|
|
|
name: "sale",
|
|
|
|
|
columns: table => new
|
|
|
|
|
{
|
|
|
|
|
sale_id = table.Column<int>(type: "integer", nullable: false)
|
|
|
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
|
|
|
sale_time = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
|
|
|
sale_cost = table.Column<int>(type: "integer", nullable: false, defaultValue: -1),
|
|
|
|
|
sale_client_id = table.Column<int>(type: "integer", nullable: true),
|
|
|
|
|
sale_employee_id = table.Column<int>(type: "integer", nullable: true)
|
|
|
|
|
},
|
|
|
|
|
constraints: table =>
|
|
|
|
|
{
|
|
|
|
|
table.PrimaryKey("PK_sale", x => x.sale_id);
|
|
|
|
|
table.ForeignKey(
|
|
|
|
|
name: "FK_sale_client_sale_client_id",
|
|
|
|
|
column: x => x.sale_client_id,
|
|
|
|
|
principalTable: "client",
|
|
|
|
|
principalColumn: "client_id",
|
|
|
|
|
onDelete: ReferentialAction.SetNull);
|
|
|
|
|
table.ForeignKey(
|
|
|
|
|
name: "FK_sale_employee_sale_employee_id",
|
|
|
|
|
column: x => x.sale_employee_id,
|
|
|
|
|
principalTable: "employee",
|
|
|
|
|
principalColumn: "employee_id",
|
|
|
|
|
onDelete: ReferentialAction.SetNull);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateTable(
|
|
|
|
|
name: "model",
|
|
|
|
|
columns: table => new
|
|
|
|
|
{
|
|
|
|
|
model_id = table.Column<int>(type: "integer", nullable: false)
|
|
|
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
|
|
|
model_name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
|
|
|
model_price = table.Column<int>(type: "integer", nullable: false, defaultValue: -1),
|
|
|
|
|
model_make_id = table.Column<int>(type: "integer", nullable: false)
|
|
|
|
|
},
|
|
|
|
|
constraints: table =>
|
|
|
|
|
{
|
|
|
|
|
table.PrimaryKey("PK_model", x => x.model_id);
|
|
|
|
|
table.ForeignKey(
|
|
|
|
|
name: "FK_model_make_model_make_id",
|
|
|
|
|
column: x => x.model_make_id,
|
|
|
|
|
principalTable: "make",
|
|
|
|
|
principalColumn: "make_id",
|
|
|
|
|
onDelete: ReferentialAction.Restrict);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateTable(
|
2024-05-05 21:21:25 +04:00
|
|
|
|
name: "sale_service",
|
2024-05-05 19:18:53 +04:00
|
|
|
|
columns: table => new
|
|
|
|
|
{
|
2024-05-05 21:21:25 +04:00
|
|
|
|
sale_id = table.Column<int>(type: "integer", nullable: false),
|
2024-05-05 19:18:53 +04:00
|
|
|
|
service_id = table.Column<int>(type: "integer", nullable: false)
|
|
|
|
|
},
|
|
|
|
|
constraints: table =>
|
|
|
|
|
{
|
2024-05-05 21:21:25 +04:00
|
|
|
|
table.PrimaryKey("PK_sale_service", x => new { x.sale_id, x.service_id });
|
2024-05-05 19:18:53 +04:00
|
|
|
|
table.ForeignKey(
|
2024-05-05 21:21:25 +04:00
|
|
|
|
name: "FK_sale_service_sale_sale_id",
|
|
|
|
|
column: x => x.sale_id,
|
2024-05-05 19:18:53 +04:00
|
|
|
|
principalTable: "sale",
|
2024-05-05 21:21:25 +04:00
|
|
|
|
principalColumn: "sale_id",
|
|
|
|
|
onDelete: ReferentialAction.Restrict);
|
|
|
|
|
table.ForeignKey(
|
|
|
|
|
name: "FK_sale_service_service_service_id",
|
|
|
|
|
column: x => x.service_id,
|
|
|
|
|
principalTable: "service",
|
|
|
|
|
principalColumn: "service_id",
|
|
|
|
|
onDelete: ReferentialAction.Cascade);
|
2024-05-05 19:18:53 +04:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateTable(
|
|
|
|
|
name: "car",
|
|
|
|
|
columns: table => new
|
|
|
|
|
{
|
|
|
|
|
car_id = table.Column<int>(type: "integer", nullable: false)
|
|
|
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
|
|
|
car_color = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "empty_string"),
|
|
|
|
|
car_releasedate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
2024-05-05 21:21:25 +04:00
|
|
|
|
car_model_id = table.Column<int>(type: "integer", nullable: false)
|
2024-05-05 19:18:53 +04:00
|
|
|
|
},
|
|
|
|
|
constraints: table =>
|
|
|
|
|
{
|
|
|
|
|
table.PrimaryKey("PK_car", x => x.car_id);
|
|
|
|
|
table.ForeignKey(
|
|
|
|
|
name: "FK_car_model_car_model_id",
|
|
|
|
|
column: x => x.car_model_id,
|
|
|
|
|
principalTable: "model",
|
|
|
|
|
principalColumn: "model_id",
|
|
|
|
|
onDelete: ReferentialAction.Restrict);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateTable(
|
|
|
|
|
name: "sale_car",
|
|
|
|
|
columns: table => new
|
|
|
|
|
{
|
|
|
|
|
sale_id = table.Column<int>(type: "integer", nullable: false),
|
|
|
|
|
car_id = table.Column<int>(type: "integer", nullable: false)
|
|
|
|
|
},
|
|
|
|
|
constraints: table =>
|
|
|
|
|
{
|
|
|
|
|
table.PrimaryKey("PK_sale_car", x => new { x.sale_id, x.car_id });
|
|
|
|
|
table.ForeignKey(
|
|
|
|
|
name: "FK_sale_car_car_car_id",
|
|
|
|
|
column: x => x.car_id,
|
|
|
|
|
principalTable: "car",
|
|
|
|
|
principalColumn: "car_id",
|
|
|
|
|
onDelete: ReferentialAction.Cascade);
|
|
|
|
|
table.ForeignKey(
|
|
|
|
|
name: "FK_sale_car_sale_sale_id",
|
|
|
|
|
column: x => x.sale_id,
|
|
|
|
|
principalTable: "sale",
|
|
|
|
|
principalColumn: "sale_id",
|
|
|
|
|
onDelete: ReferentialAction.Restrict);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_car_car_model_id",
|
|
|
|
|
table: "car",
|
|
|
|
|
column: "car_model_id");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
2024-05-05 21:21:25 +04:00
|
|
|
|
name: "IX_client_client_phonenumber",
|
2024-05-05 19:18:53 +04:00
|
|
|
|
table: "client",
|
2024-05-05 21:21:25 +04:00
|
|
|
|
column: "client_phonenumber",
|
2024-05-05 19:18:53 +04:00
|
|
|
|
unique: true);
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_employee_employee_email",
|
|
|
|
|
table: "employee",
|
|
|
|
|
column: "employee_email",
|
|
|
|
|
unique: true);
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_make_make_name",
|
|
|
|
|
table: "make",
|
|
|
|
|
column: "make_name",
|
|
|
|
|
unique: true);
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_model_model_make_id",
|
|
|
|
|
table: "model",
|
|
|
|
|
column: "model_make_id");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_model_model_name",
|
|
|
|
|
table: "model",
|
|
|
|
|
column: "model_name",
|
|
|
|
|
unique: true);
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_sale_sale_client_id",
|
|
|
|
|
table: "sale",
|
|
|
|
|
column: "sale_client_id");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_sale_sale_employee_id",
|
|
|
|
|
table: "sale",
|
|
|
|
|
column: "sale_employee_id");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_sale_car_car_id",
|
|
|
|
|
table: "sale_car",
|
|
|
|
|
column: "car_id");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_sale_service_service_id",
|
|
|
|
|
table: "sale_service",
|
|
|
|
|
column: "service_id");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.CreateIndex(
|
|
|
|
|
name: "IX_service_service_name",
|
|
|
|
|
table: "service",
|
|
|
|
|
column: "service_name",
|
|
|
|
|
unique: true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
|
|
|
{
|
|
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "sale_car");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "sale_service");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "car");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.DropTable(
|
2024-05-05 21:21:25 +04:00
|
|
|
|
name: "sale");
|
2024-05-05 19:18:53 +04:00
|
|
|
|
|
|
|
|
|
migrationBuilder.DropTable(
|
2024-05-05 21:21:25 +04:00
|
|
|
|
name: "service");
|
2024-05-05 19:18:53 +04:00
|
|
|
|
|
|
|
|
|
migrationBuilder.DropTable(
|
2024-05-05 21:21:25 +04:00
|
|
|
|
name: "model");
|
2024-05-05 19:18:53 +04:00
|
|
|
|
|
|
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "client");
|
|
|
|
|
|
|
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "employee");
|
2024-05-05 21:21:25 +04:00
|
|
|
|
|
|
|
|
|
migrationBuilder.DropTable(
|
|
|
|
|
name: "make");
|
2024-05-05 19:18:53 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|