Files
shield 16160f6424 feat: initial datamodel + ef connection and migrations
Initial version of the data model
Includes EF initialization and migrations
EF migrations are applied on application start
2026-04-09 10:36:09 +02:00

245 lines
9.8 KiB
C#

using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace TournamentOrganizer.Migrations
{
/// <inheritdoc />
public partial class InitialDataModel : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Games",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: false),
S1RuleSet = table.Column<int>(type: "INTEGER", nullable: false),
S2RuleSet = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Games", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Teams",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Teams", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Tournaments",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
GameId = table.Column<int>(type: "INTEGER", nullable: false),
EventId = table.Column<int>(type: "INTEGER", nullable: false),
S1RuleSet = table.Column<int>(type: "INTEGER", nullable: false),
S2RuleSet = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Tournaments", x => x.Id);
table.ForeignKey(
name: "FK_Tournaments_Events_EventId",
column: x => x.EventId,
principalTable: "Events",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Tournaments_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("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Contact = table.Column<string>(type: "TEXT", nullable: false),
TeamId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Players", x => x.Id);
table.ForeignKey(
name: "FK_Players_Teams_TeamId",
column: x => x.TeamId,
principalTable: "Teams",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Matches",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
TournamentId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Matches", x => x.Id);
table.ForeignKey(
name: "FK_Matches_Tournaments_TournamentId",
column: x => x.TournamentId,
principalTable: "Tournaments",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Rounds",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
MatchId = table.Column<int>(type: "INTEGER", nullable: false),
WinnerId = table.Column<int>(type: "INTEGER", nullable: true),
State = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Rounds", x => x.Id);
table.ForeignKey(
name: "FK_Rounds_Matches_MatchId",
column: x => x.MatchId,
principalTable: "Matches",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "TeamParticipants",
columns: table => new
{
MatchId = table.Column<int>(type: "INTEGER", nullable: false),
TeamId = table.Column<int>(type: "INTEGER", nullable: false),
Seed = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TeamParticipants", x => new { x.MatchId, x.TeamId });
table.ForeignKey(
name: "FK_TeamParticipants_Matches_MatchId",
column: x => x.MatchId,
principalTable: "Matches",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_TeamParticipants_Teams_TeamId",
column: x => x.TeamId,
principalTable: "Teams",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PlayerParticipants",
columns: table => new
{
RoundId = table.Column<int>(type: "INTEGER", nullable: false),
PlayerId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PlayerParticipants", x => new { x.RoundId, x.PlayerId });
table.ForeignKey(
name: "FK_PlayerParticipants_Players_PlayerId",
column: x => x.PlayerId,
principalTable: "Players",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PlayerParticipants_Rounds_RoundId",
column: x => x.RoundId,
principalTable: "Rounds",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Matches_TournamentId",
table: "Matches",
column: "TournamentId");
migrationBuilder.CreateIndex(
name: "IX_PlayerParticipants_PlayerId",
table: "PlayerParticipants",
column: "PlayerId");
migrationBuilder.CreateIndex(
name: "IX_Players_TeamId",
table: "Players",
column: "TeamId");
migrationBuilder.CreateIndex(
name: "IX_Rounds_MatchId",
table: "Rounds",
column: "MatchId");
migrationBuilder.CreateIndex(
name: "IX_TeamParticipants_TeamId",
table: "TeamParticipants",
column: "TeamId");
migrationBuilder.CreateIndex(
name: "IX_Tournaments_EventId",
table: "Tournaments",
column: "EventId");
migrationBuilder.CreateIndex(
name: "IX_Tournaments_GameId",
table: "Tournaments",
column: "GameId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PlayerParticipants");
migrationBuilder.DropTable(
name: "TeamParticipants");
migrationBuilder.DropTable(
name: "Players");
migrationBuilder.DropTable(
name: "Rounds");
migrationBuilder.DropTable(
name: "Teams");
migrationBuilder.DropTable(
name: "Matches");
migrationBuilder.DropTable(
name: "Tournaments");
migrationBuilder.DropTable(
name: "Games");
}
}
}