using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace CarShowroomDatabaseStorage.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "client", columns: table => new { client_id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), client_name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "empty_string"), client_phonenumber = table.Column(type: "character varying(25)", maxLength: 25, nullable: false) }, constraints: table => { table.PrimaryKey("PK_client", x => x.client_id); }); migrationBuilder.CreateTable( name: "employee", columns: table => new { employee_id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), employee_name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "empty_string"), employee_email = table.Column(type: "character varying(40)", maxLength: 40, nullable: false), employee_password = table.Column(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(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), make_name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) }, constraints: table => { table.PrimaryKey("PK_make", x => x.make_id); }); migrationBuilder.CreateTable( name: "service", columns: table => new { service_id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), service_name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), service_cost = table.Column(type: "integer", nullable: false, defaultValue: -1) }, constraints: table => { table.PrimaryKey("PK_service", x => x.service_id); }); migrationBuilder.CreateTable( name: "sale", columns: table => new { sale_id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), sale_time = table.Column(type: "timestamp with time zone", nullable: false), sale_cost = table.Column(type: "integer", nullable: false, defaultValue: -1), sale_client_id = table.Column(type: "integer", nullable: true), sale_employee_id = table.Column(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(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), model_name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), model_price = table.Column(type: "integer", nullable: false, defaultValue: -1), model_make_id = table.Column(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( name: "sale_service", columns: table => new { sale_id = table.Column(type: "integer", nullable: false), service_id = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_sale_service", x => new { x.sale_id, x.service_id }); table.ForeignKey( name: "FK_sale_service_sale_sale_id", column: x => x.sale_id, principalTable: "sale", 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); }); migrationBuilder.CreateTable( name: "car", columns: table => new { car_id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), car_color = table.Column(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "empty_string"), car_releasedate = table.Column(type: "timestamp with time zone", nullable: false), car_model_id = table.Column(type: "integer", nullable: false) }, 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(type: "integer", nullable: false), car_id = table.Column(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( name: "IX_client_client_phonenumber", table: "client", column: "client_phonenumber", 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); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "sale_car"); migrationBuilder.DropTable( name: "sale_service"); migrationBuilder.DropTable( name: "car"); migrationBuilder.DropTable( name: "sale"); migrationBuilder.DropTable( name: "service"); migrationBuilder.DropTable( name: "model"); migrationBuilder.DropTable( name: "client"); migrationBuilder.DropTable( name: "employee"); migrationBuilder.DropTable( name: "make"); } } }