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
Branches
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 (
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
CREATE TABLE participants (
user_id int NOT NULL REFERENCES users(user_id),
......@@ -100,11 +108,10 @@ CREATE TYPE part_state AS ENUM (
CREATE TABLE participations (
user_id int NOT NULL REFERENCES users(user_id),
round_id int NOT NULL REFERENCES rounds(round_id),
region int NOT NULL REFERENCES places(place_id), -- ve kterém kraji apod. účastník soutěží
place int NOT NULL REFERENCES places(place_id), -- konkrétní soutěžní místo (default: region)
contest_id int NOT NULL REFERENCES contests(contest_id),
place_id int NOT NULL REFERENCES places(place_id), -- konkrétní soutěžní místo (default: region contestu)
state part_state NOT NULL,
PRIMARY KEY (user_id, round_id)
PRIMARY KEY (user_id, contest_id)
);
-- Úloha
......@@ -183,6 +190,7 @@ CREATE TYPE log_type AS ENUM (
'user', -- users(user_id)
'place', -- places(place_id)
'round', -- rounds(round_id)
'contest', -- contests(contest_id)
'participant', -- participants(user_id)
'task', -- tasks(task_id)
'user_role' -- user_roles(user_id)
......
......@@ -120,12 +120,25 @@ class User(Base):
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):
general = auto()
user = auto()
place = auto()
round = auto()
contest = auto()
participant = auto()
task = auto()
user_role = auto()
......@@ -168,14 +181,12 @@ class Participation(Base):
__tablename__ = 'participations'
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)
region = Column(Integer, ForeignKey('places.place_id'), nullable=False)
place = Column(Integer, ForeignKey('places.place_id'), nullable=False)
contest_id = Column(Integer, ForeignKey('contests.contest_id'), primary_key=True, nullable=False)
place_id = Column(Integer, ForeignKey('places.place_id'), nullable=False)
state = Column(Enum(PartState, name='part_state'), nullable=False)
place_object = relationship('Place', primaryjoin='Participation.place == Place.place_id')
region_object = relationship('Place', primaryjoin='Participation.region == Place.place_id')
round = relationship('Round')
contest = relationship('Contest', primaryjoin='Participation.contest_id == Contest.contest_id')
place = relationship('Place', primaryjoin='Participation.place_id == Place.place_id')
user = relationship('User')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment