Description
Refactor the Player model to follow database normalization practices. Extract Position, Team, and League into their own tables, reducing data redundancy and improving data integrity.
ERD

DDL
CREATE TABLE IF NOT EXISTS "leagues" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
"name" TEXT NOT NULL UNIQUE,
"country" TEXT NOT NULL,
"confederation" TEXT
);
CREATE TABLE IF NOT EXISTS "teams" (
-- https://liaison.reuters.com/tools/sports-team-codes
"id" TEXT PRIMARY KEY,
"name" TEXT NOT NULL UNIQUE,
"leagueId" INTEGER NOT NULL,
FOREIGN KEY ("leagueId") REFERENCES "leagues"("id") ON UPDATE NO ACTION ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS "positions" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL,
CHECK (
id = 'GK' AND name = 'Goalkeeper'
OR id = 'RB' AND name = 'Right-Back'
OR id = 'LB' AND name = 'Left-Back'
OR id = 'CB' AND name = 'Centre-Back'
OR id = 'DM' AND name = 'Defensive Midfield'
OR id = 'CM' AND name = 'Central Midfield'
OR id = 'RW' AND name = 'Right Winger'
OR id = 'AM' AND name = 'Attacking Midfield'
OR id = 'CF' AND name = 'Centre-Forward'
OR id = 'SS' AND name = 'Second Striker'
OR id = 'LW' AND name = 'Left Winger'
)
);
CREATE TABLE IF NOT EXISTS "players" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
"firstName" TEXT NOT NULL,
"middleName" TEXT,
"lastName" TEXT NOT NULL,
"dateOfBirth" TEXT,
"squadNumber" INTEGER NOT NULL UNIQUE,
"positionId" TEXT NOT NULL,
"teamId" TEXT NOT NULL,
"starting11" BOOLEAN,
FOREIGN KEY ("positionId") REFERENCES "positions"("id") ON UPDATE NO ACTION ON DELETE NO ACTION,
FOREIGN KEY ("teamId") REFERENCES "teams"("id") ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE INDEX IF NOT EXISTS "idx_teams_leagueId" ON "teams"("leagueId");
CREATE INDEX IF NOT EXISTS "idx_players_positionId" ON "players"("positionId");
CREATE INDEX IF NOT EXISTS "idx_players_teamId" ON "players"("teamId");
Acceptance Criteria
- Create new tables for
Position, Team, and League.
- Modify the
Player table to use foreign keys referencing the new tables.
- Migrate existing data to match the new schema.
- Write integration tests to verify proper data relationships.
Description
Refactor the
Playermodel to follow database normalization practices. ExtractPosition,Team, andLeagueinto their own tables, reducing data redundancy and improving data integrity.ERD
DDL
Acceptance Criteria
Position,Team, andLeague.Playertable to use foreign keys referencing the new tables.