using System; using Microsoft.EntityFrameworkCore.Migrations; using NetTopologySuite.Geometries; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace AutobusApi.Infrastructure.Data.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.EnsureSchema( name: "domain"); migrationBuilder.AlterDatabase() .Annotation("Npgsql:PostgresExtension:postgis", ",,"); migrationBuilder.CreateTable( name: "carriages", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), type = table.Column(type: "varchar(16)", nullable: false), capacity = table.Column(type: "int", nullable: false), number = table.Column(type: "int", nullable: false), has_wifi = table.Column(type: "boolean", nullable: false), has_outlets = table.Column(type: "boolean", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_carriages", x => x.id); }); migrationBuilder.CreateTable( name: "companies", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), name = table.Column(type: "varchar(64)", nullable: false), legal_address = table.Column(type: "varchar(256)", nullable: false), contact_email = table.Column(type: "varchar(256)", nullable: false), contact_phone_number = table.Column(type: "varchar(16)", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_companies", x => x.id); }); migrationBuilder.CreateTable( name: "countries", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), name = table.Column(type: "varchar(64)", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_countries", x => x.id); }); migrationBuilder.CreateTable( name: "routes", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_routes", x => x.id); }); migrationBuilder.CreateTable( name: "ticket_documents", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), type = table.Column(type: "varchar(32)", nullable: false), information = table.Column(type: "varchar(256)", nullable: false), ticket_group_id = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ticket_documents", x => x.id); }); migrationBuilder.CreateTable( name: "users", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), identity_id = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_users", x => x.id); }); migrationBuilder.CreateTable( name: "employees", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), first_name = table.Column(type: "varchar(32)", nullable: false), last_name = table.Column(type: "varchar(32)", nullable: false), patronymic = table.Column(type: "varchar(32)", nullable: false), sex = table.Column(type: "varchar(16)", nullable: false), birth_date = table.Column(type: "date", nullable: false), identity_id = table.Column(type: "int", nullable: false), employer_company_id = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_employees", x => x.id); table.ForeignKey( name: "fk_employees_companies_employerCompanyId", column: x => x.employer_company_id, principalSchema: "domain", principalTable: "companies", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "vehicles", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), company_id = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_vehicles", x => x.id); table.ForeignKey( name: "fk_vehicles_companies_companyId", column: x => x.company_id, principalSchema: "domain", principalTable: "companies", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "regions", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), name = table.Column(type: "varchar(64)", nullable: false), country_id = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_regions", x => x.id); table.ForeignKey( name: "fk_regions_coutries_countryId", column: x => x.country_id, principalSchema: "domain", principalTable: "countries", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "ticket_groups", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), buyer_first_name = table.Column(type: "varchar(32)", nullable: false), buyer_last_name = table.Column(type: "varchar(32)", nullable: false), buyer_phone_number = table.Column(type: "varchar(16)", nullable: false), buyer_email = table.Column(type: "varchar(256)", nullable: false), passenger_first_name = table.Column(type: "varchar(32)", nullable: false), passenger_last_name = table.Column(type: "varchar(32)", nullable: false), passenger_patronymic = table.Column(type: "varchar(32)", nullable: false), passenger_sex = table.Column(type: "varchar(16)", nullable: false), passenger_birth_date = table.Column(type: "date", nullable: false), purchase_timestamp_utc = table.Column(type: "timestamptz", nullable: false), is_returned = table.Column(type: "boolean", nullable: false), user_id = table.Column(type: "int", nullable: true), TicketDocumentId = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ticket_groups", x => x.id); table.ForeignKey( name: "fk_ticketGroups_ticketDocuments_ticketDocumentId", column: x => x.TicketDocumentId, principalSchema: "domain", principalTable: "ticket_documents", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_ticketGroups_users_userId", column: x => x.user_id, principalSchema: "domain", principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "employee_documents", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), type = table.Column(type: "varchar(32)", nullable: false), information = table.Column(type: "varchar(256)", nullable: false), employee_id = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_employee_documents", x => x.id); table.ForeignKey( name: "fk_employeeDocuments_employees_employeeId", column: x => x.employee_id, principalSchema: "domain", principalTable: "employees", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "aircrafts", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false), number = table.Column(type: "varchar(8)", nullable: false), model = table.Column(type: "varchar(64)", nullable: false), capacity = table.Column(type: "int", nullable: false), has_wifi = table.Column(type: "boolean", nullable: false), has_multimedia = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_aircrafts", x => x.id); table.ForeignKey( name: "fk_aircrafts_vehicles_id", column: x => x.id, principalSchema: "domain", principalTable: "vehicles", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "buses", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false), number = table.Column(type: "varchar(8)", nullable: false), model = table.Column(type: "varchar(64)", nullable: false), capacity = table.Column(type: "int", nullable: false), has_climate_control = table.Column(type: "boolean", nullable: false), has_wc = table.Column(type: "boolean", nullable: false), has_wifi = table.Column(type: "boolean", nullable: false), has_multimedia = table.Column(type: "boolean", nullable: false), has_outlets = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_buses", x => x.id); table.ForeignKey( name: "fk_buses_vehicles_id", column: x => x.id, principalSchema: "domain", principalTable: "vehicles", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "trains", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false), number = table.Column(type: "varchar(8)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_trains", x => x.id); table.ForeignKey( name: "fk_trains_vehicles_id", column: x => x.id, principalSchema: "domain", principalTable: "vehicles", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "vehicle_enrollments", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), departure_timestamp_utc = table.Column(type: "timestamptz", nullable: false), vehicle_id = table.Column(type: "int", nullable: false), route_id = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_vehicle_enrollments", x => x.id); table.ForeignKey( name: "fk_vehicleEnrollments_routes_routeId", column: x => x.route_id, principalSchema: "domain", principalTable: "routes", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_vehicleEnrollments_vehicles_vehicleId", column: x => x.vehicle_id, principalSchema: "domain", principalTable: "vehicles", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "cities", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), name = table.Column(type: "varchar(64)", nullable: false), region_id = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_cities", x => x.id); table.ForeignKey( name: "fk_cities_regions_regionId", column: x => x.region_id, principalSchema: "domain", principalTable: "regions", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "train_carriages", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), train_id = table.Column(type: "int", nullable: false), carriage_id = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_train_carriages", x => x.id); table.ForeignKey( name: "fk_trainCarriages_trains_carriageId", column: x => x.train_id, principalSchema: "domain", principalTable: "carriages", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_trainCarriages_trains_trainId", column: x => x.train_id, principalSchema: "domain", principalTable: "trains", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "reviews", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), rating = table.Column(type: "numeric(1,0)", nullable: false), comment = table.Column(type: "varchar(128)", nullable: false), post_timestamp_utc = table.Column(type: "timestamptz", nullable: false), user_id = table.Column(type: "int", nullable: false), vehicle_enrollment_id = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_reviews", x => x.id); table.ForeignKey( name: "fk_reviews_users_userId", column: x => x.user_id, principalSchema: "domain", principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_reviews_vehicleEnrollments_vehicleEnrollmentId", column: x => x.vehicle_enrollment_id, principalSchema: "domain", principalTable: "vehicle_enrollments", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "tickets", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), ticket_group_id = table.Column(type: "int", nullable: false), vehicle_enrollment_id = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_tickets", x => x.id); table.ForeignKey( name: "fk_tickets_ticketGroups_ticketGroupId", column: x => x.ticket_group_id, principalSchema: "domain", principalTable: "ticket_groups", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tickets_vehicleEnrollments_vehicleEnrollmentId", column: x => x.vehicle_enrollment_id, principalSchema: "domain", principalTable: "vehicle_enrollments", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "vehicle_enrollment_employees", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), employee_id = table.Column(type: "int", nullable: false), vehicle_enrollment_id = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_vehicle_enrollment_employees", x => x.id); table.ForeignKey( name: "fk_vehicleEnrollmentEmployees_employees_employeeId", column: x => x.employee_id, principalSchema: "domain", principalTable: "employees", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_vehicleEnrollmentEmployees_vehicleEnrollments_vehicleEnrollmentId", column: x => x.vehicle_enrollment_id, principalSchema: "domain", principalTable: "vehicle_enrollments", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "addresses", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), name = table.Column(type: "varchar(64)", nullable: false), location = table.Column(type: "geography(point)", nullable: false), vehicle_type = table.Column(type: "varchar(16)", nullable: false), city_id = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_addresses", x => x.id); table.ForeignKey( name: "fk_addresses_city_id", column: x => x.city_id, principalSchema: "domain", principalTable: "cities", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "route_addresses", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), order = table.Column(type: "int", nullable: false), address_id = table.Column(type: "int", nullable: false), route_id = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_route_addresses", x => x.id); table.ForeignKey( name: "fk_routeAddresses_addresses_addressId", column: x => x.address_id, principalSchema: "domain", principalTable: "addresses", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_routeAddresses_routes_routeId", column: x => x.route_id, principalSchema: "domain", principalTable: "routes", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "route_address_details", schema: "domain", columns: table => new { id = table.Column(type: "int", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), time_to_next_address = table.Column(type: "interval", nullable: false), cost_to_next_address = table.Column(type: "numeric(16,4)", nullable: false), current_address_stop_time = table.Column(type: "interval", nullable: false), route_address_id = table.Column(type: "int", nullable: false), vehicle_enrollment_id = table.Column(type: "int", nullable: false), is_deleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_route_address_details", x => x.id); table.ForeignKey( name: "fk_routeAddressDetails_routeAddress_routeAddressId", column: x => x.route_address_id, principalSchema: "domain", principalTable: "route_addresses", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_routeAddressDetails_vehicleEnrollments_vehicleEnrollmentId", column: x => x.vehicle_enrollment_id, principalSchema: "domain", principalTable: "vehicle_enrollments", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_addresses_city_id", schema: "domain", table: "addresses", column: "city_id"); migrationBuilder.CreateIndex( name: "IX_cities_region_id", schema: "domain", table: "cities", column: "region_id"); migrationBuilder.CreateIndex( name: "IX_employee_documents_employee_id", schema: "domain", table: "employee_documents", column: "employee_id"); migrationBuilder.CreateIndex( name: "IX_employees_employer_company_id", schema: "domain", table: "employees", column: "employer_company_id"); migrationBuilder.CreateIndex( name: "IX_employees_identity_id", schema: "domain", table: "employees", column: "identity_id", unique: true); migrationBuilder.CreateIndex( name: "IX_regions_country_id", schema: "domain", table: "regions", column: "country_id"); migrationBuilder.CreateIndex( name: "IX_reviews_user_id", schema: "domain", table: "reviews", column: "user_id"); migrationBuilder.CreateIndex( name: "IX_reviews_vehicle_enrollment_id", schema: "domain", table: "reviews", column: "vehicle_enrollment_id"); migrationBuilder.CreateIndex( name: "IX_route_address_details_route_address_id", schema: "domain", table: "route_address_details", column: "route_address_id"); migrationBuilder.CreateIndex( name: "IX_route_address_details_vehicle_enrollment_id", schema: "domain", table: "route_address_details", column: "vehicle_enrollment_id"); migrationBuilder.CreateIndex( name: "IX_route_addresses_address_id", schema: "domain", table: "route_addresses", column: "address_id"); migrationBuilder.CreateIndex( name: "IX_route_addresses_route_id", schema: "domain", table: "route_addresses", column: "route_id"); migrationBuilder.CreateIndex( name: "IX_ticket_groups_TicketDocumentId", schema: "domain", table: "ticket_groups", column: "TicketDocumentId", unique: true); migrationBuilder.CreateIndex( name: "IX_ticket_groups_user_id", schema: "domain", table: "ticket_groups", column: "user_id"); migrationBuilder.CreateIndex( name: "IX_tickets_ticket_group_id", schema: "domain", table: "tickets", column: "ticket_group_id"); migrationBuilder.CreateIndex( name: "IX_tickets_vehicle_enrollment_id", schema: "domain", table: "tickets", column: "vehicle_enrollment_id"); migrationBuilder.CreateIndex( name: "IX_train_carriages_train_id", schema: "domain", table: "train_carriages", column: "train_id"); migrationBuilder.CreateIndex( name: "IX_users_identity_id", schema: "domain", table: "users", column: "identity_id", unique: true); migrationBuilder.CreateIndex( name: "IX_vehicle_enrollment_employees_employee_id", schema: "domain", table: "vehicle_enrollment_employees", column: "employee_id"); migrationBuilder.CreateIndex( name: "IX_vehicle_enrollment_employees_vehicle_enrollment_id", schema: "domain", table: "vehicle_enrollment_employees", column: "vehicle_enrollment_id"); migrationBuilder.CreateIndex( name: "IX_vehicle_enrollments_route_id", schema: "domain", table: "vehicle_enrollments", column: "route_id"); migrationBuilder.CreateIndex( name: "IX_vehicle_enrollments_vehicle_id", schema: "domain", table: "vehicle_enrollments", column: "vehicle_id"); migrationBuilder.CreateIndex( name: "IX_vehicles_company_id", schema: "domain", table: "vehicles", column: "company_id"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "aircrafts", schema: "domain"); migrationBuilder.DropTable( name: "buses", schema: "domain"); migrationBuilder.DropTable( name: "employee_documents", schema: "domain"); migrationBuilder.DropTable( name: "reviews", schema: "domain"); migrationBuilder.DropTable( name: "route_address_details", schema: "domain"); migrationBuilder.DropTable( name: "tickets", schema: "domain"); migrationBuilder.DropTable( name: "train_carriages", schema: "domain"); migrationBuilder.DropTable( name: "vehicle_enrollment_employees", schema: "domain"); migrationBuilder.DropTable( name: "route_addresses", schema: "domain"); migrationBuilder.DropTable( name: "ticket_groups", schema: "domain"); migrationBuilder.DropTable( name: "carriages", schema: "domain"); migrationBuilder.DropTable( name: "trains", schema: "domain"); migrationBuilder.DropTable( name: "employees", schema: "domain"); migrationBuilder.DropTable( name: "vehicle_enrollments", schema: "domain"); migrationBuilder.DropTable( name: "addresses", schema: "domain"); migrationBuilder.DropTable( name: "ticket_documents", schema: "domain"); migrationBuilder.DropTable( name: "users", schema: "domain"); migrationBuilder.DropTable( name: "routes", schema: "domain"); migrationBuilder.DropTable( name: "vehicles", schema: "domain"); migrationBuilder.DropTable( name: "cities", schema: "domain"); migrationBuilder.DropTable( name: "companies", schema: "domain"); migrationBuilder.DropTable( name: "regions", schema: "domain"); migrationBuilder.DropTable( name: "countries", schema: "domain"); } } }