Added missing relations on database

This commit is contained in:
2026-05-14 14:16:50 +01:00
parent 8bce9df5a1
commit 80db4dd531
5 changed files with 587 additions and 12 deletions
@@ -0,0 +1,506 @@
// <auto-generated />
using System;
using BeReadyBackend;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace BeReadyBackend.Migrations
{
[DbContext(typeof(BeReadyDbContext))]
[Migration("20260514131334_AddedMissingRelations")]
partial class AddedMissingRelations
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.20")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("BeReadyBackend.Models.Achievement", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Label")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Achievements");
});
modelBuilder.Entity("BeReadyBackend.Models.Designation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Label")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Designations");
});
modelBuilder.Entity("BeReadyBackend.Models.Group", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreationDate")
.HasColumnType("datetime2");
b.Property<string>("Label")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Groups");
});
modelBuilder.Entity("BeReadyBackend.Models.Message", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("GroupId")
.HasColumnType("int");
b.Property<string>("Libelle")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("SendDate")
.HasColumnType("datetime2");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("GroupId");
b.HasIndex("UserId");
b.ToTable("Messages");
});
modelBuilder.Entity("BeReadyBackend.Models.Post", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreationDate")
.HasColumnType("datetime2");
b.Property<string>("Libelle")
.HasColumnType("nvarchar(max)");
b.Property<int>("Likes")
.HasColumnType("int");
b.Property<int>("RandomChallengeId")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("RandomChallengeId");
b.HasIndex("UserId");
b.ToTable("Posts");
});
modelBuilder.Entity("BeReadyBackend.Models.RandomChallenge", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime?>("GeneratedAt")
.HasColumnType("datetime2");
b.Property<bool>("IsAlreadyPast")
.HasColumnType("bit");
b.Property<string>("Label")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Libelle")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("RandomChallenges");
});
modelBuilder.Entity("BeReadyBackend.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreationDate")
.HasColumnType("datetime2");
b.Property<int?>("DesignationId")
.HasColumnType("int");
b.Property<string>("Email")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasMaxLength(60)
.HasColumnType("nvarchar(60)");
b.Property<string>("Salt")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Series")
.HasColumnType("int");
b.Property<int>("TotalChallenge")
.HasColumnType("int");
b.Property<int>("TotalLikes")
.HasColumnType("int");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("DesignationId");
b.ToTable("Users");
});
modelBuilder.Entity("BeReadyBackend.Models.UserAchievement", b =>
{
b.Property<int>("UserId")
.HasColumnType("int");
b.Property<int>("AchievementId")
.HasColumnType("int");
b.HasKey("UserId", "AchievementId");
b.HasIndex("AchievementId");
b.ToTable("UserAchievements");
});
modelBuilder.Entity("BeReadyBackend.Models.UserFriend", b =>
{
b.Property<int>("UserId")
.HasColumnType("int");
b.Property<int>("FriendId")
.HasColumnType("int");
b.Property<bool>("IsAccepted")
.HasColumnType("bit");
b.HasKey("UserId", "FriendId");
b.HasIndex("FriendId");
b.ToTable("UserFriends");
});
modelBuilder.Entity("BeReadyBackend.Models.UserGroup", b =>
{
b.Property<int>("UserId")
.HasColumnType("int");
b.Property<int>("GroupId")
.HasColumnType("int");
b.Property<string>("Grade")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("UserId", "GroupId");
b.HasIndex("GroupId");
b.ToTable("UserGroups");
});
modelBuilder.Entity("BeReadyBackend.Models.UserPost", b =>
{
b.Property<int>("UserId")
.HasColumnType("int");
b.Property<int>("PostId")
.HasColumnType("int");
b.HasKey("UserId", "PostId");
b.HasIndex("PostId");
b.ToTable("UserPosts");
});
modelBuilder.Entity("BeReadyBackend.Models.UserRandomChallenge", b =>
{
b.Property<int>("UserId")
.HasColumnType("int");
b.Property<int>("RandomChallengeId")
.HasColumnType("int");
b.Property<string>("Proof")
.HasColumnType("nvarchar(max)");
b.HasKey("UserId", "RandomChallengeId");
b.HasIndex("RandomChallengeId");
b.ToTable("UserRandomChallenges");
});
modelBuilder.Entity("BeReadyBackend.Models.Message", b =>
{
b.HasOne("BeReadyBackend.Models.Group", "Group")
.WithMany("Messages")
.HasForeignKey("GroupId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeReadyBackend.Models.User", "User")
.WithMany("Messages")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Group");
b.Navigation("User");
});
modelBuilder.Entity("BeReadyBackend.Models.Post", b =>
{
b.HasOne("BeReadyBackend.Models.RandomChallenge", "RandomChallenge")
.WithMany("Posts")
.HasForeignKey("RandomChallengeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeReadyBackend.Models.User", "User")
.WithMany("Posts")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("RandomChallenge");
b.Navigation("User");
});
modelBuilder.Entity("BeReadyBackend.Models.User", b =>
{
b.HasOne("BeReadyBackend.Models.Designation", "Designation")
.WithMany("Users")
.HasForeignKey("DesignationId");
b.Navigation("Designation");
});
modelBuilder.Entity("BeReadyBackend.Models.UserAchievement", b =>
{
b.HasOne("BeReadyBackend.Models.Achievement", "Achievement")
.WithMany("UserAchievements")
.HasForeignKey("AchievementId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeReadyBackend.Models.User", "User")
.WithMany("UserAchievements")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Achievement");
b.Navigation("User");
});
modelBuilder.Entity("BeReadyBackend.Models.UserFriend", b =>
{
b.HasOne("BeReadyBackend.Models.User", "Friend")
.WithMany()
.HasForeignKey("FriendId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("BeReadyBackend.Models.User", "User")
.WithMany("UserFriends")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Friend");
b.Navigation("User");
});
modelBuilder.Entity("BeReadyBackend.Models.UserGroup", b =>
{
b.HasOne("BeReadyBackend.Models.Group", "Group")
.WithMany("UserGroups")
.HasForeignKey("GroupId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeReadyBackend.Models.User", "User")
.WithMany("UserGroups")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Group");
b.Navigation("User");
});
modelBuilder.Entity("BeReadyBackend.Models.UserPost", b =>
{
b.HasOne("BeReadyBackend.Models.Post", "Post")
.WithMany("UserPosts")
.HasForeignKey("PostId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeReadyBackend.Models.User", "User")
.WithMany("UserPosts")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Post");
b.Navigation("User");
});
modelBuilder.Entity("BeReadyBackend.Models.UserRandomChallenge", b =>
{
b.HasOne("BeReadyBackend.Models.RandomChallenge", "RandomChallenge")
.WithMany("UserRandomChallenges")
.HasForeignKey("RandomChallengeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeReadyBackend.Models.User", "User")
.WithMany("UserRandomChallenges")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("RandomChallenge");
b.Navigation("User");
});
modelBuilder.Entity("BeReadyBackend.Models.Achievement", b =>
{
b.Navigation("UserAchievements");
});
modelBuilder.Entity("BeReadyBackend.Models.Designation", b =>
{
b.Navigation("Users");
});
modelBuilder.Entity("BeReadyBackend.Models.Group", b =>
{
b.Navigation("Messages");
b.Navigation("UserGroups");
});
modelBuilder.Entity("BeReadyBackend.Models.Post", b =>
{
b.Navigation("UserPosts");
});
modelBuilder.Entity("BeReadyBackend.Models.RandomChallenge", b =>
{
b.Navigation("Posts");
b.Navigation("UserRandomChallenges");
});
modelBuilder.Entity("BeReadyBackend.Models.User", b =>
{
b.Navigation("Messages");
b.Navigation("Posts");
b.Navigation("UserAchievements");
b.Navigation("UserFriends");
b.Navigation("UserGroups");
b.Navigation("UserPosts");
b.Navigation("UserRandomChallenges");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,50 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BeReadyBackend.Migrations
{
/// <inheritdoc />
public partial class AddedMissingRelations : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "RandomChallengeId",
table: "Posts",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateIndex(
name: "IX_Posts_RandomChallengeId",
table: "Posts",
column: "RandomChallengeId");
migrationBuilder.AddForeignKey(
name: "FK_Posts_RandomChallenges_RandomChallengeId",
table: "Posts",
column: "RandomChallengeId",
principalTable: "RandomChallenges",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Posts_RandomChallenges_RandomChallengeId",
table: "Posts");
migrationBuilder.DropIndex(
name: "IX_Posts_RandomChallengeId",
table: "Posts");
migrationBuilder.DropColumn(
name: "RandomChallengeId",
table: "Posts");
}
}
}
@@ -40,7 +40,7 @@ namespace BeReadyBackend.Migrations
b.HasKey("Id");
b.ToTable("Achievements", (string)null);
b.ToTable("Achievements");
});
modelBuilder.Entity("BeReadyBackend.Models.Designation", b =>
@@ -57,7 +57,7 @@ namespace BeReadyBackend.Migrations
b.HasKey("Id");
b.ToTable("Designations", (string)null);
b.ToTable("Designations");
});
modelBuilder.Entity("BeReadyBackend.Models.Group", b =>
@@ -77,7 +77,7 @@ namespace BeReadyBackend.Migrations
b.HasKey("Id");
b.ToTable("Groups", (string)null);
b.ToTable("Groups");
});
modelBuilder.Entity("BeReadyBackend.Models.Message", b =>
@@ -107,7 +107,7 @@ namespace BeReadyBackend.Migrations
b.HasIndex("UserId");
b.ToTable("Messages", (string)null);
b.ToTable("Messages");
});
modelBuilder.Entity("BeReadyBackend.Models.Post", b =>
@@ -127,14 +127,19 @@ namespace BeReadyBackend.Migrations
b.Property<int>("Likes")
.HasColumnType("int");
b.Property<int>("RandomChallengeId")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("RandomChallengeId");
b.HasIndex("UserId");
b.ToTable("Posts", (string)null);
b.ToTable("Posts");
});
modelBuilder.Entity("BeReadyBackend.Models.RandomChallenge", b =>
@@ -161,7 +166,7 @@ namespace BeReadyBackend.Migrations
b.HasKey("Id");
b.ToTable("RandomChallenges", (string)null);
b.ToTable("RandomChallenges");
});
modelBuilder.Entity("BeReadyBackend.Models.User", b =>
@@ -217,7 +222,7 @@ namespace BeReadyBackend.Migrations
b.HasIndex("DesignationId");
b.ToTable("Users", (string)null);
b.ToTable("Users");
});
modelBuilder.Entity("BeReadyBackend.Models.UserAchievement", b =>
@@ -232,7 +237,7 @@ namespace BeReadyBackend.Migrations
b.HasIndex("AchievementId");
b.ToTable("UserAchievements", (string)null);
b.ToTable("UserAchievements");
});
modelBuilder.Entity("BeReadyBackend.Models.UserFriend", b =>
@@ -250,7 +255,7 @@ namespace BeReadyBackend.Migrations
b.HasIndex("FriendId");
b.ToTable("UserFriends", (string)null);
b.ToTable("UserFriends");
});
modelBuilder.Entity("BeReadyBackend.Models.UserGroup", b =>
@@ -269,7 +274,7 @@ namespace BeReadyBackend.Migrations
b.HasIndex("GroupId");
b.ToTable("UserGroups", (string)null);
b.ToTable("UserGroups");
});
modelBuilder.Entity("BeReadyBackend.Models.UserPost", b =>
@@ -284,7 +289,7 @@ namespace BeReadyBackend.Migrations
b.HasIndex("PostId");
b.ToTable("UserPosts", (string)null);
b.ToTable("UserPosts");
});
modelBuilder.Entity("BeReadyBackend.Models.UserRandomChallenge", b =>
@@ -302,7 +307,7 @@ namespace BeReadyBackend.Migrations
b.HasIndex("RandomChallengeId");
b.ToTable("UserRandomChallenges", (string)null);
b.ToTable("UserRandomChallenges");
});
modelBuilder.Entity("BeReadyBackend.Models.Message", b =>
@@ -326,12 +331,20 @@ namespace BeReadyBackend.Migrations
modelBuilder.Entity("BeReadyBackend.Models.Post", b =>
{
b.HasOne("BeReadyBackend.Models.RandomChallenge", "RandomChallenge")
.WithMany("Posts")
.HasForeignKey("RandomChallengeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeReadyBackend.Models.User", "User")
.WithMany("Posts")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("RandomChallenge");
b.Navigation("User");
});
@@ -463,6 +476,8 @@ namespace BeReadyBackend.Migrations
modelBuilder.Entity("BeReadyBackend.Models.RandomChallenge", b =>
{
b.Navigation("Posts");
b.Navigation("UserRandomChallenges");
});
+3
View File
@@ -11,6 +11,9 @@ public class Post
public User? User { get; set; }
[Required] public int UserId { get; set; }
public RandomChallenge? RandomChallenge { get; set; }
[Required] public int RandomChallengeId { get; set; }
public List<UserPost>? UserPosts { get; set; }
}
+1
View File
@@ -12,4 +12,5 @@ public class RandomChallenge
public DateTime? GeneratedAt { get; set; }
public List<UserRandomChallenge>? UserRandomChallenges { get; set; }
public List<Post>? Posts { get; set; }
}