using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace DrinkRateAPI.Migrations { /// public partial class init : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "AspNetRoles", columns: table => new { Id = table.Column(type: "text", nullable: false), Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), ConcurrencyStamp = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_AspNetRoles", x => x.Id); }); migrationBuilder.CreateTable( name: "AspNetUsers", columns: table => new { Id = table.Column(type: "text", nullable: false), UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), EmailConfirmed = table.Column(type: "boolean", nullable: false), PasswordHash = table.Column(type: "text", nullable: true), SecurityStamp = table.Column(type: "text", nullable: true), ConcurrencyStamp = table.Column(type: "text", nullable: true), PhoneNumber = table.Column(type: "text", nullable: true), PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), TwoFactorEnabled = table.Column(type: "boolean", nullable: false), LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), LockoutEnabled = table.Column(type: "boolean", nullable: false), AccessFailedCount = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AspNetUsers", x => x.Id); }); 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: "AspNetRoleClaims", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), RoleId = table.Column(type: "text", nullable: false), ClaimType = table.Column(type: "text", nullable: true), ClaimValue = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); table.ForeignKey( name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", column: x => x.RoleId, principalTable: "AspNetRoles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "AspNetUserClaims", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "text", nullable: false), ClaimType = table.Column(type: "text", nullable: true), ClaimValue = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); table.ForeignKey( name: "FK_AspNetUserClaims_AspNetUsers_UserId", column: x => x.UserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "AspNetUserLogins", columns: table => new { LoginProvider = table.Column(type: "text", nullable: false), ProviderKey = table.Column(type: "text", nullable: false), ProviderDisplayName = table.Column(type: "text", nullable: true), UserId = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); table.ForeignKey( name: "FK_AspNetUserLogins_AspNetUsers_UserId", column: x => x.UserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "AspNetUserRoles", columns: table => new { UserId = table.Column(type: "text", nullable: false), RoleId = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); table.ForeignKey( name: "FK_AspNetUserRoles_AspNetRoles_RoleId", column: x => x.RoleId, principalTable: "AspNetRoles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_AspNetUserRoles_AspNetUsers_UserId", column: x => x.UserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "AspNetUserTokens", columns: table => new { UserId = table.Column(type: "text", nullable: false), LoginProvider = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: false), Value = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); table.ForeignKey( name: "FK_AspNetUserTokens_AspNetUsers_UserId", column: x => x.UserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserProfiles", 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), ApplicationUserId = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserProfiles", x => x.Id); table.ForeignKey( name: "FK_UserProfiles_AspNetUsers_ApplicationUserId", column: x => x.ApplicationUserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); 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: "DbCompanyTableViewDbUserProfile", columns: table => new { CompanyTableViewsId = table.Column(type: "uuid", nullable: false), UserProfilesId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DbCompanyTableViewDbUserProfile", x => new { x.CompanyTableViewsId, x.UserProfilesId }); table.ForeignKey( name: "FK_DbCompanyTableViewDbUserProfile_CompanyTableViews_CompanyTa~", column: x => x.CompanyTableViewsId, principalTable: "CompanyTableViews", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_DbCompanyTableViewDbUserProfile_UserProfiles_UserProfilesId", column: x => x.UserProfilesId, principalTable: "UserProfiles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "DbProductTableViewDbUserProfile", columns: table => new { ProductTableViewsId = table.Column(type: "uuid", nullable: false), UserProfilesId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DbProductTableViewDbUserProfile", x => new { x.ProductTableViewsId, x.UserProfilesId }); table.ForeignKey( name: "FK_DbProductTableViewDbUserProfile_ProductTableView_ProductTab~", column: x => x.ProductTableViewsId, principalTable: "ProductTableView", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_DbProductTableViewDbUserProfile_UserProfiles_UserProfilesId", column: x => x.UserProfilesId, principalTable: "UserProfiles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserProfileCompanyTableStats", 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_UserProfileCompanyTableStats", x => new { x.UserId, x.CompanyTableId }); table.ForeignKey( name: "FK_UserProfileCompanyTableStats_CompanyTables_CompanyTableId", column: x => x.CompanyTableId, principalTable: "CompanyTables", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserProfileCompanyTableStats_UserProfiles_UserId", column: x => x.UserId, principalTable: "UserProfiles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserProfileProductTableStats", 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_UserProfileProductTableStats", x => new { x.UserId, x.ProductTableId }); table.ForeignKey( name: "FK_UserProfileProductTableStats_ProductTable_ProductTableId", column: x => x.ProductTableId, principalTable: "ProductTable", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserProfileProductTableStats_UserProfiles_UserId", column: x => x.UserId, principalTable: "UserProfiles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "CompanyRatings", columns: table => new { UserProfileId = 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.UserProfileId, 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_UserProfiles_UserProfileId", column: x => x.UserProfileId, principalTable: "UserProfiles", 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 { UserProfileId = 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.UserProfileId, 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_UserProfiles_UserProfileId", column: x => x.UserProfileId, principalTable: "UserProfiles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_AspNetRoleClaims_RoleId", table: "AspNetRoleClaims", column: "RoleId"); migrationBuilder.CreateIndex( name: "RoleNameIndex", table: "AspNetRoles", column: "NormalizedName", unique: true); migrationBuilder.CreateIndex( name: "IX_AspNetUserClaims_UserId", table: "AspNetUserClaims", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_AspNetUserLogins_UserId", table: "AspNetUserLogins", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_AspNetUserRoles_RoleId", table: "AspNetUserRoles", column: "RoleId"); migrationBuilder.CreateIndex( name: "EmailIndex", table: "AspNetUsers", column: "NormalizedEmail"); migrationBuilder.CreateIndex( name: "UserNameIndex", table: "AspNetUsers", column: "NormalizedUserName", unique: true); 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_DbCompanyTableViewDbUserProfile_UserProfilesId", table: "DbCompanyTableViewDbUserProfile", column: "UserProfilesId"); migrationBuilder.CreateIndex( name: "IX_DbProductTableDbProductTableView_ProductTablesId", table: "DbProductTableDbProductTableView", column: "ProductTablesId"); migrationBuilder.CreateIndex( name: "IX_DbProductTableViewDbUserProfile_UserProfilesId", table: "DbProductTableViewDbUserProfile", column: "UserProfilesId"); 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_UserProfileCompanyTableStats_CompanyTableId", table: "UserProfileCompanyTableStats", column: "CompanyTableId"); migrationBuilder.CreateIndex( name: "IX_UserProfileProductTableStats_ProductTableId", table: "UserProfileProductTableStats", column: "ProductTableId"); migrationBuilder.CreateIndex( name: "IX_UserProfiles_ApplicationUserId", table: "UserProfiles", column: "ApplicationUserId", unique: true); migrationBuilder.CreateIndex( name: "IX_UserProfiles_UserName", table: "UserProfiles", column: "UserName", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "AspNetRoleClaims"); migrationBuilder.DropTable( name: "AspNetUserClaims"); migrationBuilder.DropTable( name: "AspNetUserLogins"); migrationBuilder.DropTable( name: "AspNetUserRoles"); migrationBuilder.DropTable( name: "AspNetUserTokens"); migrationBuilder.DropTable( name: "CompanyRatings"); migrationBuilder.DropTable( name: "DbCompanyTableDbCompanyTableView"); migrationBuilder.DropTable( name: "DbCompanyTableViewDbUserProfile"); migrationBuilder.DropTable( name: "DbProductTableDbProductTableView"); migrationBuilder.DropTable( name: "DbProductTableViewDbUserProfile"); migrationBuilder.DropTable( name: "ProductRating"); migrationBuilder.DropTable( name: "UserProfileCompanyTableStats"); migrationBuilder.DropTable( name: "UserProfileProductTableStats"); migrationBuilder.DropTable( name: "AspNetRoles"); migrationBuilder.DropTable( name: "CompanyTableViews"); migrationBuilder.DropTable( name: "ProductTableView"); migrationBuilder.DropTable( name: "Product"); migrationBuilder.DropTable( name: "UserProfiles"); migrationBuilder.DropTable( name: "Companies"); migrationBuilder.DropTable( name: "ProductTable"); migrationBuilder.DropTable( name: "AspNetUsers"); migrationBuilder.DropTable( name: "CompanyTables"); } } }