using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace DrinkRateAPI.Migrations { /// public partial class BaseDbModel : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "CompanyTables", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CompanyTableName = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_CompanyTables", x => x.Id); }); migrationBuilder.CreateTable( name: "CompanyTableViews", columns: table => new { Id = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_CompanyTableViews", x => x.Id); }); migrationBuilder.CreateTable( name: "ProductTable", columns: table => new { Id = table.Column(type: "uuid", nullable: false), ProductTableName = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ProductTable", x => x.Id); }); migrationBuilder.CreateTable( name: "ProductTableView", columns: table => new { Id = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ProductTableView", x => x.Id); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserName = table.Column(type: "text", nullable: false), IsAdmin = table.Column(type: "boolean", nullable: false), IsDeleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "Companies", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CompanyTableId = table.Column(type: "uuid", nullable: false), CompanyName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), RatingSum = table.Column(type: "bigint", nullable: false), RatingCount = table.Column(type: "bigint", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Companies", x => x.Id); table.ForeignKey( name: "FK_Companies_CompanyTables_CompanyTableId", column: x => x.CompanyTableId, principalTable: "CompanyTables", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "DbCompanyTableDbCompanyTableView", columns: table => new { CompanyTablesId = table.Column(type: "uuid", nullable: false), DbCompanyTableViewId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DbCompanyTableDbCompanyTableView", x => new { x.CompanyTablesId, x.DbCompanyTableViewId }); table.ForeignKey( name: "FK_DbCompanyTableDbCompanyTableView_CompanyTableViews_DbCompan~", column: x => x.DbCompanyTableViewId, principalTable: "CompanyTableViews", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_DbCompanyTableDbCompanyTableView_CompanyTables_CompanyTable~", column: x => x.CompanyTablesId, principalTable: "CompanyTables", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "DbProductTableDbProductTableView", columns: table => new { DbProductTableViewId = table.Column(type: "uuid", nullable: false), ProductTablesId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DbProductTableDbProductTableView", x => new { x.DbProductTableViewId, x.ProductTablesId }); table.ForeignKey( name: "FK_DbProductTableDbProductTableView_ProductTableView_DbProduct~", column: x => x.DbProductTableViewId, principalTable: "ProductTableView", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_DbProductTableDbProductTableView_ProductTable_ProductTables~", column: x => x.ProductTablesId, principalTable: "ProductTable", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "DbCompanyTableViewDbUser", columns: table => new { CompanyTableViewsId = table.Column(type: "uuid", nullable: false), UsersId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DbCompanyTableViewDbUser", x => new { x.CompanyTableViewsId, x.UsersId }); table.ForeignKey( name: "FK_DbCompanyTableViewDbUser_CompanyTableViews_CompanyTableView~", column: x => x.CompanyTableViewsId, principalTable: "CompanyTableViews", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_DbCompanyTableViewDbUser_Users_UsersId", column: x => x.UsersId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "DbProductTableViewDbUser", columns: table => new { ProductTableViewsId = table.Column(type: "uuid", nullable: false), UsersId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DbProductTableViewDbUser", x => new { x.ProductTableViewsId, x.UsersId }); table.ForeignKey( name: "FK_DbProductTableViewDbUser_ProductTableView_ProductTableViews~", column: x => x.ProductTableViewsId, principalTable: "ProductTableView", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_DbProductTableViewDbUser_Users_UsersId", column: x => x.UsersId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserCompanyTableStats", columns: table => new { UserId = table.Column(type: "uuid", nullable: false), CompanyTableId = table.Column(type: "uuid", nullable: false), RatingCount = table.Column(type: "integer", nullable: false), HighestRatingCount = table.Column(type: "integer", nullable: false), Credits = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserCompanyTableStats", x => new { x.UserId, x.CompanyTableId }); table.ForeignKey( name: "FK_UserCompanyTableStats_CompanyTables_CompanyTableId", column: x => x.CompanyTableId, principalTable: "CompanyTables", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserCompanyTableStats_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserProductTableStats", columns: table => new { UserId = table.Column(type: "uuid", nullable: false), ProductTableId = table.Column(type: "uuid", nullable: false), RatingCount = table.Column(type: "integer", nullable: false), HighestRatingCount = table.Column(type: "integer", nullable: false), Credits = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserProductTableStats", x => new { x.UserId, x.ProductTableId }); table.ForeignKey( name: "FK_UserProductTableStats_ProductTable_ProductTableId", column: x => x.ProductTableId, principalTable: "ProductTable", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserProductTableStats_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "CompanyRatings", columns: table => new { UserId = table.Column(type: "uuid", nullable: false), CompanyId = table.Column(type: "uuid", nullable: false), Rating = table.Column(type: "smallint", nullable: false), Comment = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_CompanyRatings", x => new { x.UserId, x.CompanyId }); table.ForeignKey( name: "FK_CompanyRatings_Companies_CompanyId", column: x => x.CompanyId, principalTable: "Companies", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_CompanyRatings_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Product", columns: table => new { Id = table.Column(type: "uuid", nullable: false), ProductTableId = table.Column(type: "uuid", nullable: false), CompanyId = table.Column(type: "uuid", nullable: false), ProductName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), RatingSum = table.Column(type: "bigint", nullable: false), RatingCount = table.Column(type: "bigint", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Product", x => x.Id); table.ForeignKey( name: "FK_Product_Companies_CompanyId", column: x => x.CompanyId, principalTable: "Companies", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Product_ProductTable_ProductTableId", column: x => x.ProductTableId, principalTable: "ProductTable", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "ProductRating", columns: table => new { UserId = table.Column(type: "uuid", nullable: false), ProductId = table.Column(type: "uuid", nullable: false), Rating = table.Column(type: "smallint", nullable: false), Comment = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_ProductRating", x => new { x.UserId, x.ProductId }); table.ForeignKey( name: "FK_ProductRating_Product_ProductId", column: x => x.ProductId, principalTable: "Product", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_ProductRating_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Companies_CompanyName", table: "Companies", column: "CompanyName", unique: true); migrationBuilder.CreateIndex( name: "IX_Companies_CompanyTableId", table: "Companies", column: "CompanyTableId"); migrationBuilder.CreateIndex( name: "IX_CompanyRatings_CompanyId", table: "CompanyRatings", column: "CompanyId"); migrationBuilder.CreateIndex( name: "IX_CompanyTables_CompanyTableName", table: "CompanyTables", column: "CompanyTableName", unique: true); migrationBuilder.CreateIndex( name: "IX_DbCompanyTableDbCompanyTableView_DbCompanyTableViewId", table: "DbCompanyTableDbCompanyTableView", column: "DbCompanyTableViewId"); migrationBuilder.CreateIndex( name: "IX_DbCompanyTableViewDbUser_UsersId", table: "DbCompanyTableViewDbUser", column: "UsersId"); migrationBuilder.CreateIndex( name: "IX_DbProductTableDbProductTableView_ProductTablesId", table: "DbProductTableDbProductTableView", column: "ProductTablesId"); migrationBuilder.CreateIndex( name: "IX_DbProductTableViewDbUser_UsersId", table: "DbProductTableViewDbUser", column: "UsersId"); migrationBuilder.CreateIndex( name: "IX_Product_CompanyId", table: "Product", column: "CompanyId"); migrationBuilder.CreateIndex( name: "IX_Product_ProductName", table: "Product", column: "ProductName", unique: true); migrationBuilder.CreateIndex( name: "IX_Product_ProductTableId", table: "Product", column: "ProductTableId"); migrationBuilder.CreateIndex( name: "IX_ProductRating_ProductId", table: "ProductRating", column: "ProductId"); migrationBuilder.CreateIndex( name: "IX_ProductTable_ProductTableName", table: "ProductTable", column: "ProductTableName", unique: true); migrationBuilder.CreateIndex( name: "IX_UserCompanyTableStats_CompanyTableId", table: "UserCompanyTableStats", column: "CompanyTableId"); migrationBuilder.CreateIndex( name: "IX_UserProductTableStats_ProductTableId", table: "UserProductTableStats", column: "ProductTableId"); migrationBuilder.CreateIndex( name: "IX_Users_UserName", table: "Users", column: "UserName", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "CompanyRatings"); migrationBuilder.DropTable( name: "DbCompanyTableDbCompanyTableView"); migrationBuilder.DropTable( name: "DbCompanyTableViewDbUser"); migrationBuilder.DropTable( name: "DbProductTableDbProductTableView"); migrationBuilder.DropTable( name: "DbProductTableViewDbUser"); migrationBuilder.DropTable( name: "ProductRating"); migrationBuilder.DropTable( name: "UserCompanyTableStats"); migrationBuilder.DropTable( name: "UserProductTableStats"); migrationBuilder.DropTable( name: "CompanyTableViews"); migrationBuilder.DropTable( name: "ProductTableView"); migrationBuilder.DropTable( name: "Product"); migrationBuilder.DropTable( name: "Users"); migrationBuilder.DropTable( name: "Companies"); migrationBuilder.DropTable( name: "ProductTable"); migrationBuilder.DropTable( name: "CompanyTables"); } } }