Skip to content
Snippets Groups Projects
Commit 22e47e75 authored by Jiří Setnička's avatar Jiří Setnička
Browse files

DB: Zavedení části kola a přidání master_round_id a master_contest_id

Budou použity pro vícedílná kola. Všechny kola/soutěže ve skupině se
budou odkazovat na stejné hlavní kolo/soutěž, operace s účastníky budou
prováděny na hlavním kole/soutěži.

Část kola je číslo 1, 2, ... a pokud je nastaveno, tak se projevuje do
kódu kola jako přilepené písmeno (70-A-3a, 70-A-3b)

Issue #178
parent 568687c1
No related branches found
No related tags found
1 merge request!48Dělená kola napotřetí
This commit is part of merge request !36. Comments created here will be created in the context of that merge request.
...@@ -90,9 +90,11 @@ CREATE TYPE score_mode AS ENUM ( ...@@ -90,9 +90,11 @@ CREATE TYPE score_mode AS ENUM (
CREATE TABLE rounds ( CREATE TABLE rounds (
round_id serial PRIMARY KEY, round_id serial PRIMARY KEY,
master_round_id int DEFAULT NULL REFERENCES rounds(round_id),
year int NOT NULL, -- ročník MO year int NOT NULL, -- ročník MO
category varchar(2) NOT NULL, -- "A", "Z5" apod. category varchar(2) NOT NULL, -- "A", "Z5" apod.
seq int NOT NULL, -- 1=domácí kolo atd. seq int NOT NULL, -- 1=domácí kolo atd.
part int NOT NULL DEFAULT 0, -- část kola (u dělených kol)
level int NOT NULL, -- úroveň hierarchie míst level int NOT NULL, -- úroveň hierarchie míst
name varchar(255) NOT NULL, -- zobrazované jméno ("Krajské kolo" apod.) name varchar(255) NOT NULL, -- zobrazované jméno ("Krajské kolo" apod.)
state round_state NOT NULL DEFAULT 'preparing', -- stav kola state round_state NOT NULL DEFAULT 'preparing', -- stav kola
...@@ -104,17 +106,22 @@ CREATE TABLE rounds ( ...@@ -104,17 +106,22 @@ CREATE TABLE rounds (
score_mode score_mode NOT NULL DEFAULT 'basic', -- mód výsledkovky score_mode score_mode NOT NULL DEFAULT 'basic', -- mód výsledkovky
score_winner_limit int DEFAULT NULL, -- bodový limit na označení za vítěze score_winner_limit int DEFAULT NULL, -- bodový limit na označení za vítěze
score_successful_limit int DEFAULT NULL, -- bodový limit na označení za úspěšného řešitele score_successful_limit int DEFAULT NULL, -- bodový limit na označení za úspěšného řešitele
UNIQUE (year, category, seq) UNIQUE (year, category, seq, part)
); );
CREATE INDEX rounds_master_round_id_index ON rounds (master_round_id);
-- Soutěže (instance kola v konkrétním místě) -- Soutěže (instance kola v konkrétním místě)
CREATE TABLE contests ( CREATE TABLE contests (
contest_id serial PRIMARY KEY, contest_id serial PRIMARY KEY,
master_contest_id int DEFAULT NULL REFERENCES contests(contest_id),
round_id int NOT NULL REFERENCES rounds(round_id), round_id int NOT NULL REFERENCES rounds(round_id),
place_id int NOT NULL REFERENCES places(place_id), place_id int NOT NULL REFERENCES places(place_id),
UNIQUE (round_id, place_id) UNIQUE (round_id, place_id)
); );
CREATE INDEX contests_master_contest_id_index ON contests (master_contest_id);
-- Detaily účastníka -- Detaily účastníka
CREATE TABLE participants ( CREATE TABLE participants (
user_id int NOT NULL REFERENCES users(user_id), user_id int NOT NULL REFERENCES users(user_id),
......
SET ROLE 'mo_osmo';
ALTER TABLE rounds
ADD COLUMN master_round_id int DEFAULT NULL REFERENCES rounds(round_id),
ADD COLUMN part int NOT NULL DEFAULT 0; -- část kola (u dělených kol)
ALTER TABLE contests
ADD COLUMN master_contest_id int DEFAULT NULL REFERENCES contests(contest_id);
ALTER TABLE rounds
DROP CONSTRAINT "rounds_year_category_seq_key",
ADD CONSTRAINT "rounds_year_category_seq_part_key" UNIQUE (year, category, seq, part);
CREATE INDEX rounds_master_round_id_index ON rounds (master_round_id);
CREATE INDEX contests_master_contest_id_index ON contests (master_contest_id);
UPDATE rounds SET master_round_id=round_id;
UPDATE contests SET master_contest_id=contest_id;
...@@ -187,13 +187,15 @@ round_score_mode_names = { ...@@ -187,13 +187,15 @@ round_score_mode_names = {
class Round(Base): class Round(Base):
__tablename__ = 'rounds' __tablename__ = 'rounds'
__table_args__ = ( __table_args__ = (
UniqueConstraint('year', 'category', 'seq'), UniqueConstraint('year', 'category', 'seq', 'part'),
) )
round_id = Column(Integer, primary_key=True, server_default=text("nextval('rounds_round_id_seq'::regclass)")) round_id = Column(Integer, primary_key=True, server_default=text("nextval('rounds_round_id_seq'::regclass)"))
master_round_id = Column(Integer, ForeignKey('rounds.round_id'))
year = Column(Integer, nullable=False) year = Column(Integer, nullable=False)
category = Column(String(2), nullable=False) category = Column(String(2), nullable=False)
seq = Column(Integer, nullable=False) seq = Column(Integer, nullable=False)
part = Column(Integer, nullable=False)
level = Column(Integer, nullable=False) level = Column(Integer, nullable=False)
name = Column(String(255), nullable=False) name = Column(String(255), nullable=False)
state = Column(Enum(RoundState, name='round_state'), nullable=False, server_default=text("'preparing'::round_state")) state = Column(Enum(RoundState, name='round_state'), nullable=False, server_default=text("'preparing'::round_state"))
...@@ -206,6 +208,8 @@ class Round(Base): ...@@ -206,6 +208,8 @@ class Round(Base):
score_winner_limit = Column(Integer) score_winner_limit = Column(Integer)
score_successful_limit = Column(Integer) score_successful_limit = Column(Integer)
master = relationship('Round', primaryjoin='Round.master_round_id == Round.round_id', remote_side='Round.round_id', post_update=True)
def round_code(self): def round_code(self):
return f"{self.year}-{self.category}-{self.seq}" return f"{self.year}-{self.category}-{self.seq}"
...@@ -275,9 +279,11 @@ class Contest(Base): ...@@ -275,9 +279,11 @@ class Contest(Base):
) )
contest_id = Column(Integer, primary_key=True, server_default=text("nextval('contests_contest_id_seq'::regclass)")) contest_id = Column(Integer, primary_key=True, server_default=text("nextval('contests_contest_id_seq'::regclass)"))
master_contest_id = Column(Integer, ForeignKey('contests.contest_id'))
round_id = Column(Integer, ForeignKey('rounds.round_id'), nullable=False) round_id = Column(Integer, ForeignKey('rounds.round_id'), nullable=False)
place_id = Column(Integer, ForeignKey('places.place_id'), nullable=False) place_id = Column(Integer, ForeignKey('places.place_id'), nullable=False)
master = relationship('Contest', primaryjoin='Contest.master_contest_id == Contest.contest_id', remote_side='Contest.contest_id', post_update=True)
place = relationship('Place') place = relationship('Place')
round = relationship('Round') round = relationship('Round')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment