using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace SlipItIn.Server.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Username = table.Column(type: "text", nullable: false), Email = table.Column(type: "text", nullable: false), PasswordHash = table.Column(type: "text", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), IsActive = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "Games", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), LobbyCode = table.Column(type: "text", nullable: false), HostId = table.Column(type: "integer", nullable: false), Status = table.Column(type: "integer", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), StartedAt = table.Column(type: "timestamp with time zone", nullable: true), EndedAt = table.Column(type: "timestamp with time zone", nullable: true), MaxPlayers = table.Column(type: "integer", nullable: false), RoundDurationSeconds = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Games", x => x.Id); table.ForeignKey( name: "FK_Games_Users_HostId", column: x => x.HostId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Phrases", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Text = table.Column(type: "text", nullable: false), CreatorId = table.Column(type: "integer", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), IsActive = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Phrases", x => x.Id); table.ForeignKey( name: "FK_Phrases_Users_CreatorId", column: x => x.CreatorId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "GameRounds", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), GameId = table.Column(type: "integer", nullable: false), RoundNumber = table.Column(type: "integer", nullable: false), Status = table.Column(type: "integer", nullable: false), StartedAt = table.Column(type: "timestamp with time zone", nullable: false), EndedAt = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_GameRounds", x => x.Id); table.ForeignKey( name: "FK_GameRounds_Games_GameId", column: x => x.GameId, principalTable: "Games", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Players", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "integer", nullable: false), GameId = table.Column(type: "integer", nullable: false), Score = table.Column(type: "integer", nullable: false), SuccessfulSlips = table.Column(type: "integer", nullable: false), FailedSlips = table.Column(type: "integer", nullable: false), JoinedAt = table.Column(type: "timestamp with time zone", nullable: false), IsReady = table.Column(type: "boolean", nullable: false), ConnectionId = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Players", x => x.Id); table.ForeignKey( name: "FK_Players_Games_GameId", column: x => x.GameId, principalTable: "Games", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Players_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "PlayerCards", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), PlayerId = table.Column(type: "integer", nullable: false), PhraseId = table.Column(type: "integer", nullable: false), GameRoundId = table.Column(type: "integer", nullable: false), IsUsed = table.Column(type: "boolean", nullable: false), AssignedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PlayerCards", x => x.Id); table.ForeignKey( name: "FK_PlayerCards_GameRounds_GameRoundId", column: x => x.GameRoundId, principalTable: "GameRounds", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_PlayerCards_Phrases_PhraseId", column: x => x.PhraseId, principalTable: "Phrases", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_PlayerCards_Players_PlayerId", column: x => x.PlayerId, principalTable: "Players", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "SlipChallenges", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), GameRoundId = table.Column(type: "integer", nullable: false), ChallengingPlayerId = table.Column(type: "integer", nullable: false), TargetPlayerId = table.Column(type: "integer", nullable: false), TargetCardId = table.Column(type: "integer", nullable: false), Status = table.Column(type: "integer", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), ResolvedAt = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_SlipChallenges", x => x.Id); table.ForeignKey( name: "FK_SlipChallenges_GameRounds_GameRoundId", column: x => x.GameRoundId, principalTable: "GameRounds", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_SlipChallenges_PlayerCards_TargetCardId", column: x => x.TargetCardId, principalTable: "PlayerCards", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_SlipChallenges_Players_ChallengingPlayerId", column: x => x.ChallengingPlayerId, principalTable: "Players", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_SlipChallenges_Players_TargetPlayerId", column: x => x.TargetPlayerId, principalTable: "Players", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( name: "IX_GameRounds_GameId", table: "GameRounds", column: "GameId"); migrationBuilder.CreateIndex( name: "IX_Games_HostId", table: "Games", column: "HostId"); migrationBuilder.CreateIndex( name: "IX_Games_LobbyCode", table: "Games", column: "LobbyCode", unique: true); migrationBuilder.CreateIndex( name: "IX_Phrases_CreatorId", table: "Phrases", column: "CreatorId"); migrationBuilder.CreateIndex( name: "IX_PlayerCards_GameRoundId", table: "PlayerCards", column: "GameRoundId"); migrationBuilder.CreateIndex( name: "IX_PlayerCards_PhraseId", table: "PlayerCards", column: "PhraseId"); migrationBuilder.CreateIndex( name: "IX_PlayerCards_PlayerId", table: "PlayerCards", column: "PlayerId"); migrationBuilder.CreateIndex( name: "IX_Players_GameId_UserId", table: "Players", columns: new[] { "GameId", "UserId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_Players_UserId", table: "Players", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_SlipChallenges_ChallengingPlayerId", table: "SlipChallenges", column: "ChallengingPlayerId"); migrationBuilder.CreateIndex( name: "IX_SlipChallenges_GameRoundId", table: "SlipChallenges", column: "GameRoundId"); migrationBuilder.CreateIndex( name: "IX_SlipChallenges_TargetCardId", table: "SlipChallenges", column: "TargetCardId"); migrationBuilder.CreateIndex( name: "IX_SlipChallenges_TargetPlayerId", table: "SlipChallenges", column: "TargetPlayerId"); migrationBuilder.CreateIndex( name: "IX_Users_Email", table: "Users", column: "Email", unique: true); migrationBuilder.CreateIndex( name: "IX_Users_Username", table: "Users", column: "Username", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "SlipChallenges"); migrationBuilder.DropTable( name: "PlayerCards"); migrationBuilder.DropTable( name: "GameRounds"); migrationBuilder.DropTable( name: "Phrases"); migrationBuilder.DropTable( name: "Players"); migrationBuilder.DropTable( name: "Games"); migrationBuilder.DropTable( name: "Users"); } } }