From c4f1f608c9ac79f29e93d276e5cbb502a3dc4368 Mon Sep 17 00:00:00 2001
From: Martin Mares <mj@ucw.cz>
Date: Tue, 28 Sep 2021 20:44:25 +0200
Subject: [PATCH] =?UTF-8?q?DB:=20=C3=9Aloha=20m=C3=A1=20typ?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 db/db.ddl               |  9 ++++++++-
 db/upgrade-20210928.sql |  8 ++++++++
 mo/db.py                | 15 +++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100644 db/upgrade-20210928.sql

diff --git a/db/db.ddl b/db/db.ddl
index 2cdf48a4..bdea19a6 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 00000000..0e0a89a2
--- /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 d7df8327..ab97e6f8 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')
 
-- 
GitLab