using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace SVSim.Database.Migrations { /// public partial class AddGuildSchema : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "GuildId", table: "Viewers", type: "integer", nullable: true); migrationBuilder.CreateTable( name: "Guilds", columns: table => new { GuildId = table.Column(type: "integer", nullable: false), Name = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Description = table.Column(type: "character varying(512)", maxLength: 512, nullable: false), LeaderViewerId = table.Column(type: "bigint", nullable: false), EmblemId = table.Column(type: "bigint", nullable: false), Activity = table.Column(type: "integer", nullable: false), JoinCondition = table.Column(type: "integer", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), BreakupAt = table.Column(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(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), GuildId = table.Column(type: "integer", nullable: false), MessageId = table.Column(type: "integer", nullable: false), AuthorViewerId = table.Column(type: "bigint", nullable: false), MessageType = table.Column(type: "integer", nullable: false), Body = table.Column(type: "text", nullable: false), DeckPayload = table.Column(type: "jsonb", nullable: true), ReplayPayload = table.Column(type: "jsonb", nullable: true), RoomPayload = table.Column(type: "jsonb", nullable: true), CreatedAt = table.Column(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(type: "integer", nullable: false), InviteeViewerId = table.Column(type: "bigint", nullable: false), InviterViewerId = table.Column(type: "bigint", nullable: false), Status = table.Column(type: "integer", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), RespondedAt = table.Column(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(type: "integer", nullable: false), ViewerId = table.Column(type: "bigint", nullable: false), Status = table.Column(type: "integer", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), RespondedAt = table.Column(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(type: "integer", nullable: false), ViewerId = table.Column(type: "bigint", nullable: false), Role = table.Column(type: "integer", nullable: false), JoinedAt = table.Column(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); } /// 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"); } } }