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

DB: Přidána tabulka score_tables pro snapshoty výsledkovek

Issue #209
parent 2a417179
No related branches found
No related tags found
1 merge request!110Zveřejňování výsledkovky účastníkům
...@@ -151,6 +151,7 @@ CREATE TABLE contests ( ...@@ -151,6 +151,7 @@ CREATE TABLE contests (
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),
state round_state NOT NULL DEFAULT 'preparing', -- používá se, pokud round.state='delegate', jinak kopíruje round.state state round_state NOT NULL DEFAULT 'preparing', -- používá se, pokud round.state='delegate', jinak kopíruje round.state
scoretable_id int DEFAULT NULL, -- odkaz na snapshot představující oficiální výsledkovou listinu soutěže
UNIQUE (round_id, place_id) UNIQUE (round_id, place_id)
); );
...@@ -439,3 +440,18 @@ CREATE TABLE scan_pages ( ...@@ -439,3 +440,18 @@ CREATE TABLE scan_pages (
-- -4 pro stránku, která nepatří do této soutěže -- -4 pro stránku, která nepatří do této soutěže
UNIQUE (job_id, file_nr, page_nr) UNIQUE (job_id, file_nr, page_nr)
); );
-- Uložené výsledkové listiny (pro zveřejnění)
CREATE TABLE score_tables (
scoretable_id serial PRIMARY KEY,
contest_id int NOT NULL REFERENCES contests(contest_id) ON DELETE CASCADE, -- soutěž ke které patří
created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- datum vytvoření snapshotu
created_by int NOT NULL REFERENCES users(user_id), -- autor snapshotu
score_mode score_mode NOT NULL, -- mód výsledkovky
note text NOT NULL, -- poznámka viditelná pro orgy
tasks jsonb NOT NULL, -- seznam názvů a kódů úloh
rows jsonb NOT NULL -- seznam řádků výsledkové listiny
);
ALTER TABLE contests ADD CONSTRAINT "contests_scoretable_id" FOREIGN KEY (scoretable_id) REFERENCES score_tables(scoretable_id);
SET ROLE 'mo_osmo';
CREATE TABLE score_tables (
scoretable_id serial PRIMARY KEY,
contest_id int NOT NULL REFERENCES contests(contest_id) ON DELETE CASCADE, -- soutěž ke které patří
created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- datum vytvoření snapshotu
created_by int NOT NULL REFERENCES users(user_id), -- autor snapshotu
score_mode score_mode NOT NULL, -- mód výsledkovky
note text NOT NULL, -- poznámka viditelná pro orgy
tasks jsonb NOT NULL, -- seznam názvů a kódů úloh
rows jsonb NOT NULL -- seznam řádků výsledkové listiny
);
ALTER TABLE contests ADD COLUMN
scoretable_id int DEFAULT NULL REFERENCES score_tables(scoretable_id);
...@@ -10,7 +10,7 @@ import re ...@@ -10,7 +10,7 @@ import re
from sqlalchemy import \ from sqlalchemy import \
Boolean, Column, DateTime, ForeignKey, Integer, String, Text, UniqueConstraint, \ Boolean, Column, DateTime, ForeignKey, Integer, String, Text, UniqueConstraint, \
text, func, \ text, func, \
create_engine, inspect, select, or_, and_ create_engine, inspect, select
from sqlalchemy.engine import Engine from sqlalchemy.engine import Engine
from sqlalchemy.orm import relationship, sessionmaker, Session, class_mapper, joinedload, aliased from sqlalchemy.orm import relationship, sessionmaker, Session, class_mapper, joinedload, aliased
from sqlalchemy.orm.attributes import get_history from sqlalchemy.orm.attributes import get_history
...@@ -391,10 +391,12 @@ class Contest(Base): ...@@ -391,10 +391,12 @@ class Contest(Base):
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)
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"))
scoretable_id = Column(Integer, ForeignKey('score_tables.scoretable_id'), nullable=True)
master = relationship('Contest', primaryjoin='Contest.master_contest_id == Contest.contest_id', remote_side='Contest.contest_id', post_update=True) 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')
scoretable = relationship('ScoreTable', primaryjoin='Contest.scoretable_id == ScoreTable.scoretable_id')
def is_subcontest(self) -> bool: def is_subcontest(self) -> bool:
return self.master_contest_id != self.contest_id return self.master_contest_id != self.contest_id
...@@ -869,6 +871,22 @@ SCAN_PAGE_CONTINUE = -3 ...@@ -869,6 +871,22 @@ SCAN_PAGE_CONTINUE = -3
SCAN_PAGE_UFO = -4 SCAN_PAGE_UFO = -4
class ScoreTable(Base):
__tablename__ = 'score_tables'
scoretable_id = Column(Integer, primary_key=True, server_default=text("nextval('score_tables_scoretable_id_seq'::regclass)"))
contest_id = Column(Integer, ForeignKey('contests.contest_id', ondelete='CASCADE'), nullable=False)
created_at = Column(DateTime(True), nullable=False, server_default=text("CURRENT_TIMESTAMP"))
created_by = Column(Integer, ForeignKey('users.user_id'), nullable=False)
score_mode = Column(Enum(RoundScoreMode, name='score_mode'), nullable=False)
note = Column(Text, nullable=False)
tasks = Column(JSONB, nullable=False)
rows = Column(JSONB, nullable=False)
user = relationship('User')
contest = relationship('Contest', primaryjoin='Contest.scoretable_id == ScoreTable.scoretable_id')
_engine: Optional[Engine] = None _engine: Optional[Engine] = None
_session: Optional[Session] = None _session: Optional[Session] = None
flask_db: Any = None flask_db: Any = None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment