diff --git a/DrinkRateAPI/Contexts/ApplicationDbContext.cs b/DrinkRateAPI/Contexts/ApplicationDbContext.cs index 7506d5d..5e30588 100644 --- a/DrinkRateAPI/Contexts/ApplicationDbContext.cs +++ b/DrinkRateAPI/Contexts/ApplicationDbContext.cs @@ -21,12 +21,13 @@ public class ApplicationDbContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { + var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); - optionsBuilder.UseNpgsql(configuration.GetConnectionString("Local")); + optionsBuilder.UseNpgsql(configuration.GetConnectionString($"Db{environment}")); } protected override void OnModelCreating(ModelBuilder modelBuilder) @@ -90,12 +91,12 @@ public class ApplicationDbContext : DbContext entity.HasMany(ctv => ctv.Users) .WithMany(u => u.CompanyTableViews); }); - + // Product modelBuilder.Entity(entity => { entity.HasKey(p => p.Id); - + entity.HasOne(p => p.ProductTable) .WithMany(pt => pt.Products) .HasForeignKey(p => p.ProductTableId); @@ -117,7 +118,7 @@ public class ApplicationDbContext : DbContext // to do: index by Sum / Count }); - + // Product Rating modelBuilder.Entity(entity => { @@ -129,7 +130,7 @@ public class ApplicationDbContext : DbContext entity.HasOne(pr => pr.Product) .WithMany(p => p.ProductRatings); }); - + // Product Table modelBuilder.Entity(entity => { @@ -142,7 +143,7 @@ public class ApplicationDbContext : DbContext entity.HasIndex(pt => pt.ProductTableName) .IsUnique(); }); - + // Product Table View modelBuilder.Entity(entity => { diff --git a/DrinkRateAPI/Migrations/20250809121142_BaseDbModel.Designer.cs b/DrinkRateAPI/Migrations/20250809121142_BaseDbModel.Designer.cs new file mode 100644 index 0000000..8f0b838 --- /dev/null +++ b/DrinkRateAPI/Migrations/20250809121142_BaseDbModel.Designer.cs @@ -0,0 +1,526 @@ +// +using System; +using DrinkRateAPI.Contexts; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DrinkRateAPI.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20250809121142_BaseDbModel")] + partial class BaseDbModel + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("DbCompanyTableDbCompanyTableView", b => + { + b.Property("CompanyTablesId") + .HasColumnType("uuid"); + + b.Property("DbCompanyTableViewId") + .HasColumnType("uuid"); + + b.HasKey("CompanyTablesId", "DbCompanyTableViewId"); + + b.HasIndex("DbCompanyTableViewId"); + + b.ToTable("DbCompanyTableDbCompanyTableView"); + }); + + modelBuilder.Entity("DbCompanyTableViewDbUser", b => + { + b.Property("CompanyTableViewsId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("CompanyTableViewsId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("DbCompanyTableViewDbUser"); + }); + + modelBuilder.Entity("DbProductTableDbProductTableView", b => + { + b.Property("DbProductTableViewId") + .HasColumnType("uuid"); + + b.Property("ProductTablesId") + .HasColumnType("uuid"); + + b.HasKey("DbProductTableViewId", "ProductTablesId"); + + b.HasIndex("ProductTablesId"); + + b.ToTable("DbProductTableDbProductTableView"); + }); + + modelBuilder.Entity("DbProductTableViewDbUser", b => + { + b.Property("ProductTableViewsId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("ProductTableViewsId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("DbProductTableViewDbUser"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompany", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CompanyName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("CompanyTableId") + .HasColumnType("uuid"); + + b.Property("RatingCount") + .HasColumnType("bigint"); + + b.Property("RatingSum") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("CompanyName") + .IsUnique(); + + b.HasIndex("CompanyTableId"); + + b.ToTable("Companies"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompanyRating", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("CompanyId") + .HasColumnType("uuid"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Rating") + .HasColumnType("smallint"); + + b.HasKey("UserId", "CompanyId"); + + b.HasIndex("CompanyId"); + + b.ToTable("CompanyRatings"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompanyTable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CompanyTableName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("CompanyTableName") + .IsUnique(); + + b.ToTable("CompanyTables"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompanyTableView", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("CompanyTableViews"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CompanyId") + .HasColumnType("uuid"); + + b.Property("ProductName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("ProductTableId") + .HasColumnType("uuid"); + + b.Property("RatingCount") + .HasColumnType("bigint"); + + b.Property("RatingSum") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("CompanyId"); + + b.HasIndex("ProductName") + .IsUnique(); + + b.HasIndex("ProductTableId"); + + b.ToTable("Product"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProductRating", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Rating") + .HasColumnType("smallint"); + + b.HasKey("UserId", "ProductId"); + + b.HasIndex("ProductId"); + + b.ToTable("ProductRating"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProductTable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ProductTableName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ProductTableName") + .IsUnique(); + + b.ToTable("ProductTable"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProductTableView", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("ProductTableView"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("IsAdmin") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserName") + .IsUnique(); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbUserCompanyTableStat", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("CompanyTableId") + .HasColumnType("uuid"); + + b.Property("Credits") + .HasColumnType("integer"); + + b.Property("HighestRatingCount") + .HasColumnType("integer"); + + b.Property("RatingCount") + .HasColumnType("integer"); + + b.HasKey("UserId", "CompanyTableId"); + + b.HasIndex("CompanyTableId"); + + b.ToTable("UserCompanyTableStats"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbUserProductTableStat", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("ProductTableId") + .HasColumnType("uuid"); + + b.Property("Credits") + .HasColumnType("integer"); + + b.Property("HighestRatingCount") + .HasColumnType("integer"); + + b.Property("RatingCount") + .HasColumnType("integer"); + + b.HasKey("UserId", "ProductTableId"); + + b.HasIndex("ProductTableId"); + + b.ToTable("UserProductTableStats"); + }); + + modelBuilder.Entity("DbCompanyTableDbCompanyTableView", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbCompanyTable", null) + .WithMany() + .HasForeignKey("CompanyTablesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbCompanyTableView", null) + .WithMany() + .HasForeignKey("DbCompanyTableViewId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DbCompanyTableViewDbUser", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbCompanyTableView", null) + .WithMany() + .HasForeignKey("CompanyTableViewsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbUser", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DbProductTableDbProductTableView", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbProductTableView", null) + .WithMany() + .HasForeignKey("DbProductTableViewId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbProductTable", null) + .WithMany() + .HasForeignKey("ProductTablesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DbProductTableViewDbUser", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbProductTableView", null) + .WithMany() + .HasForeignKey("ProductTableViewsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbUser", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompany", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbCompanyTable", "CompanyTable") + .WithMany("Companies") + .HasForeignKey("CompanyTableId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CompanyTable"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompanyRating", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbCompany", "Company") + .WithMany("CompanyRatings") + .HasForeignKey("CompanyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbUser", "User") + .WithMany("CompanyRatings") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Company"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProduct", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbCompany", "Company") + .WithMany("Products") + .HasForeignKey("CompanyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbProductTable", "ProductTable") + .WithMany("Products") + .HasForeignKey("ProductTableId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Company"); + + b.Navigation("ProductTable"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProductRating", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbProduct", "Product") + .WithMany("ProductRatings") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbUser", "User") + .WithMany("ProductRatings") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbUserCompanyTableStat", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbCompanyTable", "CompanyTable") + .WithMany() + .HasForeignKey("CompanyTableId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbUser", "User") + .WithMany("UserCompanyTableStats") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CompanyTable"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbUserProductTableStat", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbProductTable", "ProductTable") + .WithMany() + .HasForeignKey("ProductTableId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbUser", "User") + .WithMany("UserProductTableStats") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ProductTable"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompany", b => + { + b.Navigation("CompanyRatings"); + + b.Navigation("Products"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompanyTable", b => + { + b.Navigation("Companies"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProduct", b => + { + b.Navigation("ProductRatings"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProductTable", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbUser", b => + { + b.Navigation("CompanyRatings"); + + b.Navigation("ProductRatings"); + + b.Navigation("UserCompanyTableStats"); + + b.Navigation("UserProductTableStats"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DrinkRateAPI/Migrations/20250809121142_BaseDbModel.cs b/DrinkRateAPI/Migrations/20250809121142_BaseDbModel.cs new file mode 100644 index 0000000..86ea95a --- /dev/null +++ b/DrinkRateAPI/Migrations/20250809121142_BaseDbModel.cs @@ -0,0 +1,460 @@ +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"); + } + } +} diff --git a/DrinkRateAPI/Migrations/ApplicationDbContextModelSnapshot.cs b/DrinkRateAPI/Migrations/ApplicationDbContextModelSnapshot.cs index 80cf503..7cc091a 100644 --- a/DrinkRateAPI/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/DrinkRateAPI/Migrations/ApplicationDbContextModelSnapshot.cs @@ -1,9 +1,10 @@ // +using System; using DrinkRateAPI.Contexts; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable @@ -17,9 +18,505 @@ namespace DrinkRateAPI.Migrations #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "9.0.8") - .HasAnnotation("Relational:MaxIdentifierLength", 128); + .HasAnnotation("Relational:MaxIdentifierLength", 63); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("DbCompanyTableDbCompanyTableView", b => + { + b.Property("CompanyTablesId") + .HasColumnType("uuid"); + + b.Property("DbCompanyTableViewId") + .HasColumnType("uuid"); + + b.HasKey("CompanyTablesId", "DbCompanyTableViewId"); + + b.HasIndex("DbCompanyTableViewId"); + + b.ToTable("DbCompanyTableDbCompanyTableView"); + }); + + modelBuilder.Entity("DbCompanyTableViewDbUser", b => + { + b.Property("CompanyTableViewsId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("CompanyTableViewsId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("DbCompanyTableViewDbUser"); + }); + + modelBuilder.Entity("DbProductTableDbProductTableView", b => + { + b.Property("DbProductTableViewId") + .HasColumnType("uuid"); + + b.Property("ProductTablesId") + .HasColumnType("uuid"); + + b.HasKey("DbProductTableViewId", "ProductTablesId"); + + b.HasIndex("ProductTablesId"); + + b.ToTable("DbProductTableDbProductTableView"); + }); + + modelBuilder.Entity("DbProductTableViewDbUser", b => + { + b.Property("ProductTableViewsId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("ProductTableViewsId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("DbProductTableViewDbUser"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompany", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CompanyName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("CompanyTableId") + .HasColumnType("uuid"); + + b.Property("RatingCount") + .HasColumnType("bigint"); + + b.Property("RatingSum") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("CompanyName") + .IsUnique(); + + b.HasIndex("CompanyTableId"); + + b.ToTable("Companies"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompanyRating", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("CompanyId") + .HasColumnType("uuid"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Rating") + .HasColumnType("smallint"); + + b.HasKey("UserId", "CompanyId"); + + b.HasIndex("CompanyId"); + + b.ToTable("CompanyRatings"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompanyTable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CompanyTableName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("CompanyTableName") + .IsUnique(); + + b.ToTable("CompanyTables"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompanyTableView", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("CompanyTableViews"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CompanyId") + .HasColumnType("uuid"); + + b.Property("ProductName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("ProductTableId") + .HasColumnType("uuid"); + + b.Property("RatingCount") + .HasColumnType("bigint"); + + b.Property("RatingSum") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("CompanyId"); + + b.HasIndex("ProductName") + .IsUnique(); + + b.HasIndex("ProductTableId"); + + b.ToTable("Product"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProductRating", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Rating") + .HasColumnType("smallint"); + + b.HasKey("UserId", "ProductId"); + + b.HasIndex("ProductId"); + + b.ToTable("ProductRating"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProductTable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ProductTableName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ProductTableName") + .IsUnique(); + + b.ToTable("ProductTable"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProductTableView", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("ProductTableView"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("IsAdmin") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserName") + .IsUnique(); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbUserCompanyTableStat", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("CompanyTableId") + .HasColumnType("uuid"); + + b.Property("Credits") + .HasColumnType("integer"); + + b.Property("HighestRatingCount") + .HasColumnType("integer"); + + b.Property("RatingCount") + .HasColumnType("integer"); + + b.HasKey("UserId", "CompanyTableId"); + + b.HasIndex("CompanyTableId"); + + b.ToTable("UserCompanyTableStats"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbUserProductTableStat", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("ProductTableId") + .HasColumnType("uuid"); + + b.Property("Credits") + .HasColumnType("integer"); + + b.Property("HighestRatingCount") + .HasColumnType("integer"); + + b.Property("RatingCount") + .HasColumnType("integer"); + + b.HasKey("UserId", "ProductTableId"); + + b.HasIndex("ProductTableId"); + + b.ToTable("UserProductTableStats"); + }); + + modelBuilder.Entity("DbCompanyTableDbCompanyTableView", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbCompanyTable", null) + .WithMany() + .HasForeignKey("CompanyTablesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbCompanyTableView", null) + .WithMany() + .HasForeignKey("DbCompanyTableViewId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DbCompanyTableViewDbUser", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbCompanyTableView", null) + .WithMany() + .HasForeignKey("CompanyTableViewsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbUser", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DbProductTableDbProductTableView", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbProductTableView", null) + .WithMany() + .HasForeignKey("DbProductTableViewId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbProductTable", null) + .WithMany() + .HasForeignKey("ProductTablesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DbProductTableViewDbUser", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbProductTableView", null) + .WithMany() + .HasForeignKey("ProductTableViewsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbUser", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompany", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbCompanyTable", "CompanyTable") + .WithMany("Companies") + .HasForeignKey("CompanyTableId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CompanyTable"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompanyRating", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbCompany", "Company") + .WithMany("CompanyRatings") + .HasForeignKey("CompanyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbUser", "User") + .WithMany("CompanyRatings") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Company"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProduct", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbCompany", "Company") + .WithMany("Products") + .HasForeignKey("CompanyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbProductTable", "ProductTable") + .WithMany("Products") + .HasForeignKey("ProductTableId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Company"); + + b.Navigation("ProductTable"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProductRating", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbProduct", "Product") + .WithMany("ProductRatings") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbUser", "User") + .WithMany("ProductRatings") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbUserCompanyTableStat", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbCompanyTable", "CompanyTable") + .WithMany() + .HasForeignKey("CompanyTableId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbUser", "User") + .WithMany("UserCompanyTableStats") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CompanyTable"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbUserProductTableStat", b => + { + b.HasOne("DrinkRateAPI.DbEntities.DbProductTable", "ProductTable") + .WithMany() + .HasForeignKey("ProductTableId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DrinkRateAPI.DbEntities.DbUser", "User") + .WithMany("UserProductTableStats") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ProductTable"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompany", b => + { + b.Navigation("CompanyRatings"); + + b.Navigation("Products"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbCompanyTable", b => + { + b.Navigation("Companies"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProduct", b => + { + b.Navigation("ProductRatings"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbProductTable", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("DrinkRateAPI.DbEntities.DbUser", b => + { + b.Navigation("CompanyRatings"); + + b.Navigation("ProductRatings"); + + b.Navigation("UserCompanyTableStats"); + + b.Navigation("UserProductTableStats"); + }); #pragma warning restore 612, 618 } } diff --git a/DrinkRateAPI/Program.cs b/DrinkRateAPI/Program.cs index e309241..f0eb316 100644 --- a/DrinkRateAPI/Program.cs +++ b/DrinkRateAPI/Program.cs @@ -52,6 +52,8 @@ builder.Services.AddSwaggerGen(c => builder.Services.AddDbContext( options => options.UseInMemoryDatabase("AppDb")); +builder.Services.AddDbContext(); + var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/DrinkRateAPI/appsettings.Development.json b/DrinkRateAPI/appsettings.Development.json deleted file mode 100644 index 6871f36..0000000 --- a/DrinkRateAPI/appsettings.Development.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "ConnectionStrings": { - "Local": "Host=localhost;Port=6942;Database=postgres;Username=postgres;Password=rum_beer_quests_mead" - } -} diff --git a/DrinkRateAPI/appsettings.json b/DrinkRateAPI/appsettings.json index 15f20a4..66a0faa 100644 --- a/DrinkRateAPI/appsettings.json +++ b/DrinkRateAPI/appsettings.json @@ -7,6 +7,6 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "Local": "Host=localhost;Port=6942;Database=postgres;Username=postgres;Password=rum_beer_quests_mead" + "DbDevelopment": "Host=localhost;Port=6942;Database=postgres;Username=postgres;Password=rum_beer_quests_mead" } }