From feecae779282b4b7bfee808e929ce41685868204 Mon Sep 17 00:00:00 2001 From: voidarc Date: Tue, 7 Jul 2026 21:20:16 +0100 Subject: [PATCH] seeding stuff --- scripts/data/divisions.csv | 1 + scripts/data/teams.csv | 4 ++-- scripts/seed.ts | 19 +++++++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/scripts/data/divisions.csv b/scripts/data/divisions.csv index 0dfcebb..b2f311e 100644 --- a/scripts/data/divisions.csv +++ b/scripts/data/divisions.csv @@ -1,4 +1,5 @@ div_name +Seniors Year 7 Year 8 Year 9 diff --git a/scripts/data/teams.csv b/scripts/data/teams.csv index 7839a8f..ba84f00 100644 --- a/scripts/data/teams.csv +++ b/scripts/data/teams.csv @@ -1,6 +1,6 @@ team_name,color +County,red East,pink -West,yellow Laud,blue School,green -County,red +West,yellow diff --git a/scripts/seed.ts b/scripts/seed.ts index fae0b45..ee014d9 100644 --- a/scripts/seed.ts +++ b/scripts/seed.ts @@ -127,9 +127,24 @@ async function seed() { const divisionId = divisionMap.get(row.division); if (!teamId) throw new Error(`Team "${row.team}" not found`); + let firstName = row.firstName; + let lastName = row.lastName; + + // If lastName is empty, default to a space (column is nullable in practice) + if (!lastName) { + lastName = ' '; + } + + // If firstName contains a space, treat the second word as lastName (only if lastName was blank) + if (lastName === ' ' && firstName && firstName.includes(' ')) { + const parts = firstName.split(' '); + firstName = parts[0]; + lastName = parts.slice(1).join(' '); + } + await db.insert(schema.players).values({ - firstName: row.firstName, - lastName: row.lastName, + firstName, + lastName, team: teamId, division: divisionId || null });