Adding group profile to the group model

This commit is contained in:
defnotken
2025-09-16 19:54:31 -05:00
parent 0df7ee424d
commit b669e2cb24
6 changed files with 1213 additions and 9 deletions

View File

@@ -74,6 +74,11 @@ public class LightlessDbContext : DbContext
mb.Entity<Group>()
.Property(g => g.CreatedDate)
.HasDefaultValueSql("CURRENT_TIMESTAMP");
mb.Entity<Group>()
.HasOne(g => g.Profile)
.WithOne(p => p.Group)
.HasForeignKey<GroupProfile>(p => p.GroupGID)
.IsRequired(false);
mb.Entity<GroupPair>().ToTable("group_pairs");
mb.Entity<GroupPair>().HasKey(u => new { u.GroupGID, u.GroupUserUID });
mb.Entity<GroupPair>().HasIndex(c => c.GroupUserUID);
@@ -85,11 +90,6 @@ public class LightlessDbContext : DbContext
mb.Entity<GroupProfile>().ToTable("group_profiles");
mb.Entity<GroupProfile>().HasKey(u => u.GroupGID);
mb.Entity<GroupProfile>().HasIndex(c => c.GroupGID);
mb.Entity<GroupProfile>()
.HasOne(gp => gp.Group)
.WithMany()
.HasForeignKey(gp => gp.GroupGID)
.OnDelete(DeleteBehavior.Cascade);
mb.Entity<GroupTempInvite>().ToTable("group_temp_invites");
mb.Entity<GroupTempInvite>().HasKey(u => new { u.GroupGID, u.Invite });
mb.Entity<GroupTempInvite>().HasIndex(c => c.GroupGID);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,41 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LightlessSyncServer.Migrations
{
/// <inheritdoc />
public partial class AddProfilesToGroup : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "fk_group_profiles_groups_group_gid",
table: "group_profiles");
migrationBuilder.AddForeignKey(
name: "fk_group_profiles_groups_group_gid",
table: "group_profiles",
column: "group_gid",
principalTable: "groups",
principalColumn: "gid");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "fk_group_profiles_groups_group_gid",
table: "group_profiles");
migrationBuilder.AddForeignKey(
name: "fk_group_profiles_groups_group_gid",
table: "group_profiles",
column: "group_gid",
principalTable: "groups",
principalColumn: "gid",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@@ -585,6 +585,7 @@ namespace LightlessSyncServer.Migrations
modelBuilder.Entity("LightlessSyncShared.Models.GroupProfile", b =>
{
b.Property<string>("GroupGID")
.HasMaxLength(20)
.HasColumnType("character varying(20)")
.HasColumnName("group_gid");
@@ -1054,10 +1055,8 @@ namespace LightlessSyncServer.Migrations
modelBuilder.Entity("LightlessSyncShared.Models.GroupProfile", b =>
{
b.HasOne("LightlessSyncShared.Models.Group", "Group")
.WithMany()
.HasForeignKey("GroupGID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.WithOne("Profile")
.HasForeignKey("LightlessSyncShared.Models.GroupProfile", "GroupGID")
.HasConstraintName("fk_group_profiles_groups_group_gid");
b.Navigation("Group");
@@ -1142,6 +1141,11 @@ namespace LightlessSyncServer.Migrations
b.Navigation("Poses");
});
modelBuilder.Entity("LightlessSyncShared.Models.Group", b =>
{
b.Navigation("Profile");
});
#pragma warning restore 612, 618
}
}

View File

@@ -11,6 +11,7 @@ public class Group
public User Owner { get; set; }
[MaxLength(50)]
public string Alias { get; set; }
public GroupProfile? Profile { get; set; }
public bool InvitesEnabled { get; set; }
public string HashedPassword { get; set; }
public bool PreferDisableSounds { get; set; }

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -7,6 +8,8 @@ using System.Threading.Tasks;
namespace LightlessSyncShared.Models;
public class GroupProfile
{
[Key]
[MaxLength(20)]
public string GroupGID { get; set; }
public Group Group { get; set; }
public string Description { get; set; }