feat(guild): add Guild aggregate schema + migration

This commit is contained in:
gamer147
2026-06-27 11:02:29 -04:00
parent 3a52115551
commit f4533aabd3
12 changed files with 5650 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,207 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace SVSim.Database.Migrations
{
/// <inheritdoc />
public partial class AddGuildSchema : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "GuildId",
table: "Viewers",
type: "integer",
nullable: true);
migrationBuilder.CreateTable(
name: "Guilds",
columns: table => new
{
GuildId = table.Column<int>(type: "integer", nullable: false),
Name = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
Description = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: false),
LeaderViewerId = table.Column<long>(type: "bigint", nullable: false),
EmblemId = table.Column<long>(type: "bigint", nullable: false),
Activity = table.Column<int>(type: "integer", nullable: false),
JoinCondition = table.Column<int>(type: "integer", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
BreakupAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Guilds", x => x.GuildId);
});
migrationBuilder.CreateTable(
name: "GuildChatMessages",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
GuildId = table.Column<int>(type: "integer", nullable: false),
MessageId = table.Column<int>(type: "integer", nullable: false),
AuthorViewerId = table.Column<long>(type: "bigint", nullable: false),
MessageType = table.Column<int>(type: "integer", nullable: false),
Body = table.Column<string>(type: "text", nullable: false),
DeckPayload = table.Column<string>(type: "jsonb", nullable: true),
ReplayPayload = table.Column<string>(type: "jsonb", nullable: true),
RoomPayload = table.Column<string>(type: "jsonb", nullable: true),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GuildChatMessages", x => x.Id);
table.ForeignKey(
name: "FK_GuildChatMessages_Guilds_GuildId",
column: x => x.GuildId,
principalTable: "Guilds",
principalColumn: "GuildId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "GuildInvites",
columns: table => new
{
GuildId = table.Column<int>(type: "integer", nullable: false),
InviteeViewerId = table.Column<long>(type: "bigint", nullable: false),
InviterViewerId = table.Column<long>(type: "bigint", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
RespondedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_GuildInvites", x => new { x.GuildId, x.InviteeViewerId });
table.ForeignKey(
name: "FK_GuildInvites_Guilds_GuildId",
column: x => x.GuildId,
principalTable: "Guilds",
principalColumn: "GuildId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "GuildJoinRequests",
columns: table => new
{
GuildId = table.Column<int>(type: "integer", nullable: false),
ViewerId = table.Column<long>(type: "bigint", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
RespondedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_GuildJoinRequests", x => new { x.GuildId, x.ViewerId });
table.ForeignKey(
name: "FK_GuildJoinRequests_Guilds_GuildId",
column: x => x.GuildId,
principalTable: "Guilds",
principalColumn: "GuildId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "GuildMembers",
columns: table => new
{
GuildId = table.Column<int>(type: "integer", nullable: false),
ViewerId = table.Column<long>(type: "bigint", nullable: false),
Role = table.Column<int>(type: "integer", nullable: false),
JoinedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GuildMembers", x => new { x.GuildId, x.ViewerId });
table.ForeignKey(
name: "FK_GuildMembers_Guilds_GuildId",
column: x => x.GuildId,
principalTable: "Guilds",
principalColumn: "GuildId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Viewers_GuildId",
table: "Viewers",
column: "GuildId");
migrationBuilder.CreateIndex(
name: "IX_GuildChatMessages_GuildId_MessageId",
table: "GuildChatMessages",
columns: new[] { "GuildId", "MessageId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_GuildInvites_InviteeViewerId_Status",
table: "GuildInvites",
columns: new[] { "InviteeViewerId", "Status" });
migrationBuilder.CreateIndex(
name: "IX_GuildJoinRequests_GuildId_Status",
table: "GuildJoinRequests",
columns: new[] { "GuildId", "Status" });
migrationBuilder.CreateIndex(
name: "IX_GuildJoinRequests_ViewerId_Status",
table: "GuildJoinRequests",
columns: new[] { "ViewerId", "Status" });
migrationBuilder.CreateIndex(
name: "IX_GuildMembers_ViewerId",
table: "GuildMembers",
column: "ViewerId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Guilds_Name",
table: "Guilds",
column: "Name");
migrationBuilder.AddForeignKey(
name: "FK_Viewers_Guilds_GuildId",
table: "Viewers",
column: "GuildId",
principalTable: "Guilds",
principalColumn: "GuildId",
onDelete: ReferentialAction.SetNull);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Viewers_Guilds_GuildId",
table: "Viewers");
migrationBuilder.DropTable(
name: "GuildChatMessages");
migrationBuilder.DropTable(
name: "GuildInvites");
migrationBuilder.DropTable(
name: "GuildJoinRequests");
migrationBuilder.DropTable(
name: "GuildMembers");
migrationBuilder.DropTable(
name: "Guilds");
migrationBuilder.DropIndex(
name: "IX_Viewers_GuildId",
table: "Viewers");
migrationBuilder.DropColumn(
name: "GuildId",
table: "Viewers");
}
}
}

View File

@@ -85,6 +85,165 @@ namespace SVSim.Database.Migrations
b.ToTable("MyPageBackgroundEntryViewer");
});
modelBuilder.Entity("SVSim.Database.Entities.Guild.Guild", b =>
{
b.Property<int>("GuildId")
.HasColumnType("integer");
b.Property<int>("Activity")
.HasColumnType("integer");
b.Property<DateTime?>("BreakupAt")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(512)
.HasColumnType("character varying(512)");
b.Property<long>("EmblemId")
.HasColumnType("bigint");
b.Property<int>("JoinCondition")
.HasColumnType("integer");
b.Property<long>("LeaderViewerId")
.HasColumnType("bigint");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.HasKey("GuildId");
b.HasIndex("Name");
b.ToTable("Guilds");
});
modelBuilder.Entity("SVSim.Database.Entities.Guild.GuildChatMessage", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<long>("AuthorViewerId")
.HasColumnType("bigint");
b.Property<string>("Body")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("DeckPayload")
.HasColumnType("jsonb");
b.Property<int>("GuildId")
.HasColumnType("integer");
b.Property<int>("MessageId")
.HasColumnType("integer");
b.Property<int>("MessageType")
.HasColumnType("integer");
b.Property<string>("ReplayPayload")
.HasColumnType("jsonb");
b.Property<string>("RoomPayload")
.HasColumnType("jsonb");
b.HasKey("Id");
b.HasIndex("GuildId", "MessageId")
.IsUnique();
b.ToTable("GuildChatMessages");
});
modelBuilder.Entity("SVSim.Database.Entities.Guild.GuildInvite", b =>
{
b.Property<int>("GuildId")
.HasColumnType("integer");
b.Property<long>("InviteeViewerId")
.HasColumnType("bigint");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<long>("InviterViewerId")
.HasColumnType("bigint");
b.Property<DateTime?>("RespondedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.HasKey("GuildId", "InviteeViewerId");
b.HasIndex("InviteeViewerId", "Status");
b.ToTable("GuildInvites");
});
modelBuilder.Entity("SVSim.Database.Entities.Guild.GuildJoinRequest", b =>
{
b.Property<int>("GuildId")
.HasColumnType("integer");
b.Property<long>("ViewerId")
.HasColumnType("bigint");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("RespondedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.HasKey("GuildId", "ViewerId");
b.HasIndex("GuildId", "Status");
b.HasIndex("ViewerId", "Status");
b.ToTable("GuildJoinRequests");
});
modelBuilder.Entity("SVSim.Database.Entities.Guild.GuildMember", b =>
{
b.Property<int>("GuildId")
.HasColumnType("integer");
b.Property<long>("ViewerId")
.HasColumnType("bigint");
b.Property<DateTime>("JoinedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("Role")
.HasColumnType("integer");
b.HasKey("GuildId", "ViewerId");
b.HasIndex("ViewerId")
.IsUnique();
b.ToTable("GuildMembers");
});
modelBuilder.Entity("SVSim.Database.Entities.Story.SpecialBattleSetting", b =>
{
b.Property<int>("Id")
@@ -2685,6 +2844,9 @@ namespace SVSim.Database.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<int?>("GuildId")
.HasColumnType("integer");
b.Property<DateTime>("LastLogin")
.HasColumnType("timestamp with time zone");
@@ -2712,6 +2874,8 @@ namespace SVSim.Database.Migrations
b.HasKey("Id");
b.HasIndex("GuildId");
b.HasIndex("ShortUdid");
b.HasIndex("Udid")
@@ -3479,6 +3643,50 @@ namespace SVSim.Database.Migrations
.IsRequired();
});
modelBuilder.Entity("SVSim.Database.Entities.Guild.GuildChatMessage", b =>
{
b.HasOne("SVSim.Database.Entities.Guild.Guild", "Guild")
.WithMany()
.HasForeignKey("GuildId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Guild");
});
modelBuilder.Entity("SVSim.Database.Entities.Guild.GuildInvite", b =>
{
b.HasOne("SVSim.Database.Entities.Guild.Guild", "Guild")
.WithMany()
.HasForeignKey("GuildId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Guild");
});
modelBuilder.Entity("SVSim.Database.Entities.Guild.GuildJoinRequest", b =>
{
b.HasOne("SVSim.Database.Entities.Guild.Guild", "Guild")
.WithMany()
.HasForeignKey("GuildId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Guild");
});
modelBuilder.Entity("SVSim.Database.Entities.Guild.GuildMember", b =>
{
b.HasOne("SVSim.Database.Entities.Guild.Guild", "Guild")
.WithMany("Members")
.HasForeignKey("GuildId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Guild");
});
modelBuilder.Entity("SVSim.Database.Entities.Story.StoryChapter", b =>
{
b.HasOne("SVSim.Database.Entities.Story.StorySection", "Section")
@@ -4112,6 +4320,11 @@ namespace SVSim.Database.Migrations
modelBuilder.Entity("SVSim.Database.Models.Viewer", b =>
{
b.HasOne("SVSim.Database.Entities.Guild.Guild", "Guild")
.WithMany()
.HasForeignKey("GuildId")
.OnDelete(DeleteBehavior.SetNull);
b.OwnsMany("SVSim.Database.Models.MyPageBgRotationEntry", "MyPageBgRotation", b1 =>
{
b1.Property<long>("ViewerId")
@@ -4588,6 +4801,8 @@ namespace SVSim.Database.Migrations
b.Navigation("GachaPointReceived");
b.Navigation("Guild");
b.Navigation("Info")
.IsRequired();
@@ -4719,6 +4934,11 @@ namespace SVSim.Database.Migrations
.IsRequired();
});
modelBuilder.Entity("SVSim.Database.Entities.Guild.Guild", b =>
{
b.Navigation("Members");
});
modelBuilder.Entity("SVSim.Database.Models.BattlePassSeasonEntry", b =>
{
b.Navigation("Rewards");