Skip to content
Snippets Groups Projects
Commit 77a48983 authored by Martin Mareš's avatar Martin Mareš Committed by Jiří Setnička
Browse files

DB: Zavedení contestů jako samostatných objektů

parent e7c30b5f
No related branches found
No related tags found
1 merge request!2Place editing
This commit is part of merge request !2. Comments created here will be created in the context of that merge request.
...@@ -79,6 +79,14 @@ CREATE TABLE rounds ( ...@@ -79,6 +79,14 @@ CREATE TABLE rounds (
UNIQUE (year, category, seq) UNIQUE (year, category, seq)
); );
-- Soutěže (instance kola v konkrétním místě)
CREATE TABLE contests (
contest_id serial PRIMARY KEY,
round int NOT NULL REFERENCES rounds(round_id),
region int NOT NULL REFERENCES places(place_id),
UNIQUE (round, region)
);
-- 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),
...@@ -100,11 +108,10 @@ CREATE TYPE part_state AS ENUM ( ...@@ -100,11 +108,10 @@ CREATE TYPE part_state AS ENUM (
CREATE TABLE participations ( CREATE TABLE participations (
user_id int NOT NULL REFERENCES users(user_id), user_id int NOT NULL REFERENCES users(user_id),
round_id int NOT NULL REFERENCES rounds(round_id), contest_id int NOT NULL REFERENCES contests(contest_id),
region int NOT NULL REFERENCES places(place_id), -- ve kterém kraji apod. účastník soutěží place_id int NOT NULL REFERENCES places(place_id), -- konkrétní soutěžní místo (default: region contestu)
place int NOT NULL REFERENCES places(place_id), -- konkrétní soutěžní místo (default: region)
state part_state NOT NULL, state part_state NOT NULL,
PRIMARY KEY (user_id, round_id) PRIMARY KEY (user_id, contest_id)
); );
-- Úloha -- Úloha
...@@ -183,6 +190,7 @@ CREATE TYPE log_type AS ENUM ( ...@@ -183,6 +190,7 @@ CREATE TYPE log_type AS ENUM (
'user', -- users(user_id) 'user', -- users(user_id)
'place', -- places(place_id) 'place', -- places(place_id)
'round', -- rounds(round_id) 'round', -- rounds(round_id)
'contest', -- contests(contest_id)
'participant', -- participants(user_id) 'participant', -- participants(user_id)
'task', -- tasks(task_id) 'task', -- tasks(task_id)
'user_role' -- user_roles(user_id) 'user_role' -- user_roles(user_id)
... ...
......
...@@ -120,12 +120,25 @@ class User(Base): ...@@ -120,12 +120,25 @@ class User(Base):
roles = relationship('UserRole', primaryjoin='UserRole.user_id == User.user_id') roles = relationship('UserRole', primaryjoin='UserRole.user_id == User.user_id')
class Contest(Base):
__tablename__ = 'contests'
__table_args__ = (
UniqueConstraint('round', 'region'),
)
contest_id = Column(Integer, primary_key=True, server_default=text("nextval('contests_contest_id_seq'::regclass)"))
round = Column(Integer, ForeignKey('rounds.round_id'), nullable=False)
region = Column(Integer, ForeignKey('places.place_id'), nullable=False)
region_object = relationship('Place')
round_object = relationship('Round')
class LogType(str, PythonEnum): class LogType(str, PythonEnum):
general = auto() general = auto()
user = auto() user = auto()
place = auto() place = auto()
round = auto() round = auto()
contest = auto()
participant = auto() participant = auto()
task = auto() task = auto()
user_role = auto() user_role = auto()
...@@ -168,14 +181,12 @@ class Participation(Base): ...@@ -168,14 +181,12 @@ class Participation(Base):
__tablename__ = 'participations' __tablename__ = 'participations'
user_id = Column(Integer, ForeignKey('users.user_id'), primary_key=True, nullable=False) user_id = Column(Integer, ForeignKey('users.user_id'), primary_key=True, nullable=False)
round_id = Column(Integer, ForeignKey('rounds.round_id'), primary_key=True, nullable=False) contest_id = Column(Integer, ForeignKey('contests.contest_id'), primary_key=True, nullable=False)
region = Column(Integer, ForeignKey('places.place_id'), nullable=False) place_id = Column(Integer, ForeignKey('places.place_id'), nullable=False)
place = Column(Integer, ForeignKey('places.place_id'), nullable=False)
state = Column(Enum(PartState, name='part_state'), nullable=False) state = Column(Enum(PartState, name='part_state'), nullable=False)
place_object = relationship('Place', primaryjoin='Participation.place == Place.place_id') contest = relationship('Contest', primaryjoin='Participation.contest_id == Contest.contest_id')
region_object = relationship('Place', primaryjoin='Participation.region == Place.place_id') place = relationship('Place', primaryjoin='Participation.place_id == Place.place_id')
round = relationship('Round')
user = relationship('User') user = relationship('User')
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment