using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace MagicCarpetDatabase.Migrations { /// public partial class FirstMigration : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Clients", columns: table => new { Id = table.Column(type: "text", nullable: false), FIO = table.Column(type: "text", nullable: false), PhoneNumber = table.Column(type: "text", nullable: false), DiscountSize = table.Column(type: "double precision", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Clients", x => x.Id); }); migrationBuilder.CreateTable( name: "Employees", columns: table => new { Id = table.Column(type: "text", nullable: false), FIO = table.Column(type: "text", nullable: false), Email = table.Column(type: "text", nullable: false), PostId = table.Column(type: "text", nullable: false), BirthDate = table.Column(type: "timestamp with time zone", nullable: false), EmploymentDate = table.Column(type: "timestamp with time zone", nullable: false), IsDeleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Employees", x => x.Id); }); migrationBuilder.CreateTable( name: "Posts", columns: table => new { Id = table.Column(type: "text", nullable: false), PostId = table.Column(type: "text", nullable: false), PostName = table.Column(type: "text", nullable: false), PostType = table.Column(type: "integer", nullable: false), Salary = table.Column(type: "double precision", nullable: false), IsActual = table.Column(type: "boolean", nullable: false), ChangeDate = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Posts", x => x.Id); }); migrationBuilder.CreateTable( name: "Tours", columns: table => new { Id = table.Column(type: "text", nullable: false), TourName = table.Column(type: "text", nullable: false), TourCountry = table.Column(type: "text", nullable: true), Price = table.Column(type: "double precision", nullable: false), TourType = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Tours", x => x.Id); }); migrationBuilder.CreateTable( name: "Salaries", columns: table => new { Id = table.Column(type: "text", nullable: false), EmployeeId = table.Column(type: "text", nullable: false), SalaryDate = table.Column(type: "timestamp with time zone", nullable: false), EmployeeSalary = table.Column(type: "double precision", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Salaries", x => x.Id); table.ForeignKey( name: "FK_Salaries_Employees_EmployeeId", column: x => x.EmployeeId, principalTable: "Employees", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Sales", columns: table => new { Id = table.Column(type: "text", nullable: false), EmployeeId = table.Column(type: "text", nullable: false), ClientId = table.Column(type: "text", nullable: true), SaleDate = table.Column(type: "timestamp with time zone", nullable: false), Sum = table.Column(type: "double precision", nullable: false), DiscountType = table.Column(type: "integer", nullable: false), Discount = table.Column(type: "double precision", nullable: false), IsCancel = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Sales", x => x.Id); table.ForeignKey( name: "FK_Sales_Clients_ClientId", column: x => x.ClientId, principalTable: "Clients", principalColumn: "Id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "FK_Sales_Employees_EmployeeId", column: x => x.EmployeeId, principalTable: "Employees", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "TourHistories", columns: table => new { Id = table.Column(type: "text", nullable: false), TourId = table.Column(type: "text", nullable: false), OldPrice = table.Column(type: "double precision", nullable: false), ChangeDate = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_TourHistories", x => x.Id); table.ForeignKey( name: "FK_TourHistories_Tours_TourId", column: x => x.TourId, principalTable: "Tours", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "SaleTours", columns: table => new { SaleId = table.Column(type: "text", nullable: false), TourId = table.Column(type: "text", nullable: false), Count = table.Column(type: "integer", nullable: false), Price = table.Column(type: "double precision", nullable: false) }, constraints: table => { table.PrimaryKey("PK_SaleTours", x => new { x.SaleId, x.TourId }); table.ForeignKey( name: "FK_SaleTours_Sales_SaleId", column: x => x.SaleId, principalTable: "Sales", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_SaleTours_Tours_TourId", column: x => x.TourId, principalTable: "Tours", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Clients_PhoneNumber", table: "Clients", column: "PhoneNumber", unique: true); migrationBuilder.CreateIndex( name: "IX_Posts_PostId_IsActual", table: "Posts", columns: new[] { "PostId", "IsActual" }, unique: true, filter: "\"IsActual\" = TRUE"); migrationBuilder.CreateIndex( name: "IX_Posts_PostName_IsActual", table: "Posts", columns: new[] { "PostName", "IsActual" }, unique: true, filter: "\"IsActual\" = TRUE"); migrationBuilder.CreateIndex( name: "IX_Salaries_EmployeeId", table: "Salaries", column: "EmployeeId"); migrationBuilder.CreateIndex( name: "IX_Sales_ClientId", table: "Sales", column: "ClientId"); migrationBuilder.CreateIndex( name: "IX_Sales_EmployeeId", table: "Sales", column: "EmployeeId"); migrationBuilder.CreateIndex( name: "IX_SaleTours_TourId", table: "SaleTours", column: "TourId"); migrationBuilder.CreateIndex( name: "IX_TourHistories_TourId", table: "TourHistories", column: "TourId"); migrationBuilder.CreateIndex( name: "IX_Tours_TourName", table: "Tours", column: "TourName", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Posts"); migrationBuilder.DropTable( name: "Salaries"); migrationBuilder.DropTable( name: "SaleTours"); migrationBuilder.DropTable( name: "TourHistories"); migrationBuilder.DropTable( name: "Sales"); migrationBuilder.DropTable( name: "Tours"); migrationBuilder.DropTable( name: "Clients"); migrationBuilder.DropTable( name: "Employees"); } } }