Files
SlipItIn/SlipItIn.Server/Migrations/20260723193505_InitialCreate.cs
Tim Krampitz d29bff17a1 Backend für "Slip It In" mit ASP.NET Core erstellt
- Neues Backend-Projekt mit Entity Framework Core (PostgreSQL) und geteilten Modellen/DTOs angelegt
- Datenbankstruktur und Migrations implementiert (User, Game, Player, Phrase, PlayerCard, GameRound, SlipChallenge)
- SignalR-Hub für Spielkommunikation (Lobby, Spielstart, Kartenvergabe, Slip/Challenge) hinzugefügt
- Spiellogik und DB-Zugriffe im GameService gekapselt
- JWT-Authentifizierung und CORS für Entwicklung konfiguriert
- Projektdateien, NuGet-Abhängigkeiten und .gitignore aktualisiert
- Startkonfiguration und Umgebungsdateien angepasst
2026-07-23 21:39:15 +02:00

320 lines
14 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace SlipItIn.Server.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Username = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
PasswordHash = table.Column<string>(type: "text", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
IsActive = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Games",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
LobbyCode = table.Column<string>(type: "text", nullable: false),
HostId = table.Column<int>(type: "integer", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
StartedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
EndedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
MaxPlayers = table.Column<int>(type: "integer", nullable: false),
RoundDurationSeconds = table.Column<int>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Text = table.Column<string>(type: "text", nullable: false),
CreatorId = table.Column<int>(type: "integer", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
IsActive = table.Column<bool>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
GameId = table.Column<int>(type: "integer", nullable: false),
RoundNumber = table.Column<int>(type: "integer", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false),
StartedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
EndedAt = table.Column<DateTime>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<int>(type: "integer", nullable: false),
GameId = table.Column<int>(type: "integer", nullable: false),
Score = table.Column<int>(type: "integer", nullable: false),
SuccessfulSlips = table.Column<int>(type: "integer", nullable: false),
FailedSlips = table.Column<int>(type: "integer", nullable: false),
JoinedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
IsReady = table.Column<bool>(type: "boolean", nullable: false),
ConnectionId = table.Column<string>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
PlayerId = table.Column<int>(type: "integer", nullable: false),
PhraseId = table.Column<int>(type: "integer", nullable: false),
GameRoundId = table.Column<int>(type: "integer", nullable: false),
IsUsed = table.Column<bool>(type: "boolean", nullable: false),
AssignedAt = table.Column<DateTime>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
GameRoundId = table.Column<int>(type: "integer", nullable: false),
ChallengingPlayerId = table.Column<int>(type: "integer", nullable: false),
TargetPlayerId = table.Column<int>(type: "integer", nullable: false),
TargetCardId = table.Column<int>(type: "integer", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
ResolvedAt = table.Column<DateTime>(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);
}
/// <inheritdoc />
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");
}
}
}