make starting_player an attribute of seeds instead of games

Since all games on a particular seed have the same starting player,
we should store this accordingly.

Note that this option is only used for old seeds (before 2020)
from the hanab.live database.

Regardless, we need to support this to be able to support these old
games.
This commit is contained in:
Maximilian Keßler 2023-07-07 14:20:24 +02:00
parent fb645b47b4
commit 3ab35eb10d
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 7 additions and 7 deletions

View file

@ -4,6 +4,7 @@ CREATE TABLE seeds (
num_players SMALLINT NOT NULL,
variant_id SMALLINT NOT NULL,
deck VARCHAR(62) NOT NULL,
starting_player SMALLINT NOT NULL DEFAULT 0,
feasible BOOLEAN DEFAULT NULL,
max_score_theoretical SMALLINT
);
@ -15,7 +16,6 @@ CREATE TABLE games (
id INT PRIMARY KEY,
seed TEXT NOT NULL REFERENCES seeds,
num_players SMALLINT NOT NULL,
starting_player SMALLINT NOT NULL DEFAULT 0,
score SMALLINT NOT NULL,
variant_id SMALLINT NOT NULL,
deck_plays BOOLEAN,

View file

@ -140,19 +140,19 @@ def detailed_export_game(
if not seed_exists:
database.cur.execute(
"INSERT INTO seeds (seed, num_players, variant_id, deck)"
"VALUES (%s, %s, %s, %s)"
"INSERT INTO seeds (seed, num_players, starting_player, variant_id, deck)"
"VALUES (%s, %s, %s, %s, %s)"
"ON CONFLICT (seed) DO NOTHING",
(seed, num_players, var_id, compressed_deck)
(seed, num_players, starting_player, var_id, compressed_deck)
)
logger.debug("New seed {} imported.".format(seed))
database.cur.execute(
"INSERT INTO games ("
"id, num_players, starting_player, score, seed, variant_id, deck_plays, one_extra_card, one_less_card,"
"id, num_players, score, seed, variant_id, deck_plays, one_extra_card, one_less_card,"
"all_or_nothing, actions"
")"
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
"ON CONFLICT (id) DO UPDATE SET ("
"deck_plays, one_extra_card, one_less_card, all_or_nothing, actions"
") = ("
@ -160,7 +160,7 @@ def detailed_export_game(
"EXCLUDED.actions"
")",
(
game_id, num_players, starting_player, score, seed, var_id, deck_plays, one_extra_card, one_less_card,
game_id, num_players, score, seed, var_id, deck_plays, one_extra_card, one_less_card,
all_or_nothing, compressed_actions
)
)