Skip to content

Commit 0ba84d5

Browse files
committed
Clean sql migration
1 parent b728d87 commit 0ba84d5

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

modules/db/src/main/resources/db/migration/V0013__player_info_and_history_tables.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ CREATE TABLE IF NOT EXISTS player_history (
2525
rapid_kfactor integer,
2626
blitz integer,
2727
blitz_kfactor integer,
28-
federation_id text,
28+
federation_id text REFERENCES federations(id),
2929
active boolean NOT NULL,
3030
created_at timestamptz NOT NULL DEFAULT NOW(),
3131
updated_at timestamptz NOT NULL DEFAULT NOW(),

modules/db/src/main/resources/db/migration/V0019__sql_cleanup.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,5 @@ DROP INDEX IF EXISTS fed_sum_rapid_players_desc_idx;
127127
DROP INDEX IF EXISTS fed_sum_blitz_players_desc_idx;
128128
DROP INDEX IF EXISTS fed_sum_players_desc_idx;
129129

130-
-- Document intentional lack of FK on player_history.federation_id
131-
COMMENT ON COLUMN player_history.federation_id IS
132-
'No FK to federations: historical records may reference dissolved federations (e.g. YUG, URS) that are not in the federations table. The LEFT JOIN in queries handles this gracefully.';
133-
134130
-- Refresh materialized view to pick up view changes
135131
REFRESH MATERIALIZED VIEW CONCURRENTLY federations_summary;

modules/db/src/test/scala/HistoryDbSuite.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ object HistoryDbSuite extends SimpleIOSuite:
129129

130130
test("availableMonths returns distinct sorted months"):
131131
resourceWithFeds.use: (historyDb, db) =>
132+
val fed = NewFederation(fedId, "United States")
132133
for
133-
_ <- db.upsert(NewPlayer(PlayerId(1), "Alice", active = true), none)
134-
_ <- historyDb.insertPlayerInfo(List(playerInfo1))
135-
_ <- historyDb.upsertPlayerHistory(List(mkHistory(1, jan2024), mkHistory(1, feb2024)))
134+
_ <- db.upsert(NewPlayer(PlayerId(1), "Alice", active = true, federationId = fedId.some), fed.some)
135+
_ <- historyDb.insertPlayerInfo(List(playerInfo1))
136+
_ <- historyDb.upsertPlayerHistory(List(mkHistory(1, jan2024), mkHistory(1, feb2024)))
136137
months <- historyDb.availableMonths
137138
yield expect(months.size == 2) and
138139
expect(months.head == feb2024) and // DESC order
@@ -168,8 +169,9 @@ object HistoryDbSuite extends SimpleIOSuite:
168169
test("playerRatingHistory returns entries in DESC order"):
169170
val mar2024 = YearMonth(2024, 3)
170171
resourceWithFeds.use: (historyDb, db) =>
172+
val fed = NewFederation(fedId, "United States")
171173
for
172-
_ <- db.upsert(NewPlayer(PlayerId(1), "Alice", active = true), none)
174+
_ <- db.upsert(NewPlayer(PlayerId(1), "Alice", active = true, federationId = fedId.some), fed.some)
173175
_ <- historyDb.insertPlayerInfo(List(playerInfo1))
174176
_ <- historyDb.upsertPlayerHistory(
175177
List(mkHistory(1, jan2024, 2700), mkHistory(1, feb2024, 2710), mkHistory(1, mar2024, 2720))
@@ -187,8 +189,9 @@ object HistoryDbSuite extends SimpleIOSuite:
187189
test("playerRatingHistory with since/until range"):
188190
val mar2024 = YearMonth(2024, 3)
189191
resourceWithFeds.use: (historyDb, db) =>
192+
val fed = NewFederation(fedId, "United States")
190193
for
191-
_ <- db.upsert(NewPlayer(PlayerId(1), "Alice", active = true), none)
194+
_ <- db.upsert(NewPlayer(PlayerId(1), "Alice", active = true, federationId = fedId.some), fed.some)
192195
_ <- historyDb.insertPlayerInfo(List(playerInfo1))
193196
_ <- historyDb.upsertPlayerHistory(
194197
List(mkHistory(1, jan2024, 2700), mkHistory(1, feb2024, 2710), mkHistory(1, mar2024, 2720))
@@ -206,8 +209,9 @@ object HistoryDbSuite extends SimpleIOSuite:
206209
test("playerRatingHistory with pagination"):
207210
val mar2024 = YearMonth(2024, 3)
208211
resourceWithFeds.use: (historyDb, db) =>
212+
val fed = NewFederation(fedId, "United States")
209213
for
210-
_ <- db.upsert(NewPlayer(PlayerId(1), "Alice", active = true), none)
214+
_ <- db.upsert(NewPlayer(PlayerId(1), "Alice", active = true, federationId = fedId.some), fed.some)
211215
_ <- historyDb.insertPlayerInfo(List(playerInfo1))
212216
_ <- historyDb.upsertPlayerHistory(
213217
List(mkHistory(1, jan2024, 2700), mkHistory(1, feb2024, 2710), mkHistory(1, mar2024, 2720))

0 commit comments

Comments
 (0)