fix: db model fixes and quote mapping

This commit is contained in:
2025-07-15 16:38:37 +02:00
parent a355c668bd
commit e2eea51a08
9 changed files with 98 additions and 31 deletions

View File

@@ -12,8 +12,8 @@ using QuotifyBE.Data;
namespace QuotifyBE.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20250714093636_initial_migration")]
partial class initial_migration
[Migration("20250715142242_revised_model")]
partial class revised_model
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -72,7 +72,7 @@ namespace QuotifyBE.Migrations
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("ImageId")
b.Property<int?>("ImageId")
.HasColumnType("integer");
b.Property<DateTime>("LastUpdatedAt")
@@ -87,6 +87,8 @@ namespace QuotifyBE.Migrations
b.HasKey("Id");
b.HasIndex("ImageId");
b.HasIndex("UserId");
b.ToTable("Quotes");
@@ -104,7 +106,7 @@ namespace QuotifyBE.Migrations
b.HasIndex("CategoryId");
b.ToTable("QuoteCategory");
b.ToTable("QuoteCategories");
});
modelBuilder.Entity("QuotifyBE.Entities.User", b =>
@@ -134,12 +136,18 @@ namespace QuotifyBE.Migrations
modelBuilder.Entity("QuotifyBE.Entities.Quote", b =>
{
b.HasOne("QuotifyBE.Entities.Image", "Image")
.WithMany()
.HasForeignKey("ImageId");
b.HasOne("QuotifyBE.Entities.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Image");
b.Navigation("User");
});
@@ -152,7 +160,7 @@ namespace QuotifyBE.Migrations
.IsRequired();
b.HasOne("QuotifyBE.Entities.Quote", "Quote")
.WithMany()
.WithMany("QuoteCategories")
.HasForeignKey("QuoteId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -161,6 +169,11 @@ namespace QuotifyBE.Migrations
b.Navigation("Quote");
});
modelBuilder.Entity("QuotifyBE.Entities.Quote", b =>
{
b.Navigation("QuoteCategories");
});
#pragma warning restore 612, 618
}
}

View File

@@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace QuotifyBE.Migrations
{
/// <inheritdoc />
public partial class initial_migration : Migration
public partial class revised_model : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
@@ -61,7 +61,7 @@ namespace QuotifyBE.Migrations
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Text = table.Column<string>(type: "text", nullable: false),
Author = table.Column<string>(type: "text", nullable: false),
ImageId = table.Column<int>(type: "integer", nullable: false),
ImageId = table.Column<int>(type: "integer", nullable: true),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
LastUpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false)
@@ -69,6 +69,11 @@ namespace QuotifyBE.Migrations
constraints: table =>
{
table.PrimaryKey("PK_Quotes", x => x.Id);
table.ForeignKey(
name: "FK_Quotes_Images_ImageId",
column: x => x.ImageId,
principalTable: "Images",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Quotes_Users_UserId",
column: x => x.UserId,
@@ -78,7 +83,7 @@ namespace QuotifyBE.Migrations
});
migrationBuilder.CreateTable(
name: "QuoteCategory",
name: "QuoteCategories",
columns: table => new
{
QuoteId = table.Column<int>(type: "integer", nullable: false),
@@ -86,15 +91,15 @@ namespace QuotifyBE.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_QuoteCategory", x => new { x.QuoteId, x.CategoryId });
table.PrimaryKey("PK_QuoteCategories", x => new { x.QuoteId, x.CategoryId });
table.ForeignKey(
name: "FK_QuoteCategory_Categories_CategoryId",
name: "FK_QuoteCategories_Categories_CategoryId",
column: x => x.CategoryId,
principalTable: "Categories",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_QuoteCategory_Quotes_QuoteId",
name: "FK_QuoteCategories_Quotes_QuoteId",
column: x => x.QuoteId,
principalTable: "Quotes",
principalColumn: "Id",
@@ -102,10 +107,15 @@ namespace QuotifyBE.Migrations
});
migrationBuilder.CreateIndex(
name: "IX_QuoteCategory_CategoryId",
table: "QuoteCategory",
name: "IX_QuoteCategories_CategoryId",
table: "QuoteCategories",
column: "CategoryId");
migrationBuilder.CreateIndex(
name: "IX_Quotes_ImageId",
table: "Quotes",
column: "ImageId");
migrationBuilder.CreateIndex(
name: "IX_Quotes_UserId",
table: "Quotes",
@@ -116,10 +126,7 @@ namespace QuotifyBE.Migrations
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Images");
migrationBuilder.DropTable(
name: "QuoteCategory");
name: "QuoteCategories");
migrationBuilder.DropTable(
name: "Categories");
@@ -127,6 +134,9 @@ namespace QuotifyBE.Migrations
migrationBuilder.DropTable(
name: "Quotes");
migrationBuilder.DropTable(
name: "Images");
migrationBuilder.DropTable(
name: "Users");
}

View File

@@ -69,7 +69,7 @@ namespace QuotifyBE.Migrations
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("ImageId")
b.Property<int?>("ImageId")
.HasColumnType("integer");
b.Property<DateTime>("LastUpdatedAt")
@@ -84,6 +84,8 @@ namespace QuotifyBE.Migrations
b.HasKey("Id");
b.HasIndex("ImageId");
b.HasIndex("UserId");
b.ToTable("Quotes");
@@ -101,7 +103,7 @@ namespace QuotifyBE.Migrations
b.HasIndex("CategoryId");
b.ToTable("QuoteCategory");
b.ToTable("QuoteCategories");
});
modelBuilder.Entity("QuotifyBE.Entities.User", b =>
@@ -131,12 +133,18 @@ namespace QuotifyBE.Migrations
modelBuilder.Entity("QuotifyBE.Entities.Quote", b =>
{
b.HasOne("QuotifyBE.Entities.Image", "Image")
.WithMany()
.HasForeignKey("ImageId");
b.HasOne("QuotifyBE.Entities.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Image");
b.Navigation("User");
});
@@ -149,7 +157,7 @@ namespace QuotifyBE.Migrations
.IsRequired();
b.HasOne("QuotifyBE.Entities.Quote", "Quote")
.WithMany()
.WithMany("QuoteCategories")
.HasForeignKey("QuoteId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -158,6 +166,11 @@ namespace QuotifyBE.Migrations
b.Navigation("Quote");
});
modelBuilder.Entity("QuotifyBE.Entities.Quote", b =>
{
b.Navigation("QuoteCategories");
});
#pragma warning restore 612, 618
}
}