using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DrinkRateAPI.Migrations
{
///
public partial class Init : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ApplicationUsers",
columns: table => new
{
Id = table.Column(type: "text", nullable: false),
UserName = table.Column(type: "text", nullable: true),
NormalizedUserName = table.Column(type: "text", nullable: true),
Email = table.Column(type: "text", nullable: true),
NormalizedEmail = table.Column(type: "text", 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_ApplicationUsers", 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: "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_ApplicationUsers_ApplicationUserId",
column: x => x.ApplicationUserId,
principalTable: "ApplicationUsers",
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_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: "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: "CompanyTableViews");
migrationBuilder.DropTable(
name: "ProductTableView");
migrationBuilder.DropTable(
name: "Product");
migrationBuilder.DropTable(
name: "UserProfiles");
migrationBuilder.DropTable(
name: "Companies");
migrationBuilder.DropTable(
name: "ProductTable");
migrationBuilder.DropTable(
name: "ApplicationUsers");
migrationBuilder.DropTable(
name: "CompanyTables");
}
}
}