diff --git a/db/db.ddl b/db/db.ddl index 2cdf48a4574b789a3b77434b169997bceca1b6e9..bdea19a60bcf3159c75bf83d7b53506201aa7088 100644 --- a/db/db.ddl +++ b/db/db.ddl @@ -179,13 +179,20 @@ CREATE TABLE participations ( CREATE INDEX participations_contest_id_index ON participations (contest_id, place_id); --- Úloha +-- Úlohy + +CREATE TYPE task_type AS ENUM ( + 'regular', -- obyčejná úloha + 'cms' -- praktická úloha kategorie P odevzdávaná přes CMS +); + CREATE TABLE tasks ( task_id serial PRIMARY KEY, round_id int NOT NULL REFERENCES rounds(round_id), code varchar(255) NOT NULL, -- např. "P-I-1" name varchar(255) NOT NULL, max_points numeric(5,1) DEFAULT NULL, -- maximální počet bodů, pokud je nastaven, nelze zadat více bodů + type task_type NOT NULL DEFAULT 'regular', UNIQUE (round_id, code) ); diff --git a/db/upgrade-20210928.sql b/db/upgrade-20210928.sql new file mode 100644 index 0000000000000000000000000000000000000000..0e0a89a299d7f7f172ea541d961b345f28073bbe --- /dev/null +++ b/db/upgrade-20210928.sql @@ -0,0 +1,8 @@ +SET ROLE 'mo_osmo'; + +CREATE TYPE task_type AS ENUM ( + 'regular', -- obyčejná úloha + 'cms' -- praktická úloha kategorie P odevzdávaná přes CMS +); + +ALTER TABLE tasks ADD COLUMN type task_type NOT NULL DEFAULT 'regular'; diff --git a/mo/db.py b/mo/db.py index d7df8327b7688bccd70f8381c822684ff56884d0..ab97e6f88a38c30e3f366ed7ff1d80f80b550173 100644 --- a/mo/db.py +++ b/mo/db.py @@ -476,6 +476,20 @@ class Participation(Base): user = relationship('User') +class TaskType(MOEnum): + regular = auto() + cms = auto() + + def friendly_name(self) -> str: + return task_type_names[self] + + +task_type_names = { + TaskType.regular: 'standardní', + TaskType.cms: 'programovací (CMS)', +} + + class Task(Base): __tablename__ = 'tasks' __table_args__ = ( @@ -487,6 +501,7 @@ class Task(Base): code = Column(String(255), nullable=False) name = Column(String(255), nullable=False) max_points = Column(Numeric) + type = Column(Enum(TaskType, name='task_type'), nullable=False, default=TaskType.regular) round = relationship('Round')