From 702a9a2010c5e5efd5151340592da8d5a252bb63 Mon Sep 17 00:00:00 2001
From: Martin Mares <mj@ucw.cz>
Date: Wed, 29 Sep 2021 22:17:39 +0200
Subject: [PATCH] =?UTF-8?q?DB:=20Zaveden=C3=AD=20custom=20k=C3=B3du=20kola?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 db/db.ddl               | 1 +
 db/upgrade-20210929.sql | 4 ++++
 mo/db.py                | 3 ++-
 3 files changed, 7 insertions(+), 1 deletion(-)
 create mode 100644 db/upgrade-20210929.sql

diff --git a/db/db.ddl b/db/db.ddl
index 2cdf48a4..d0841c54 100644
--- a/db/db.ddl
+++ b/db/db.ddl
@@ -115,6 +115,7 @@ CREATE TABLE rounds (
 	seq		int		NOT NULL,			-- 1=domácí kolo atd.
 	part		int		NOT NULL DEFAULT 0,		-- část kola (nenulová u dělených kol)
 	level		int		NOT NULL,			-- úroveň hierarchie míst
+	code		varchar(255)	NOT NULL DEFAULT '',		-- kód kola ("1", "S" apod.), prázdný=podle seq
 	name		varchar(255)	NOT NULL,			-- zobrazované jméno ("Krajské kolo" apod.)
 	state		round_state	NOT NULL DEFAULT 'preparing',	-- stav kola
 	tasks_file	varchar(255)	DEFAULT NULL,			-- jméno souboru se zadáním úloh
diff --git a/db/upgrade-20210929.sql b/db/upgrade-20210929.sql
new file mode 100644
index 00000000..d48a0349
--- /dev/null
+++ b/db/upgrade-20210929.sql
@@ -0,0 +1,4 @@
+SET ROLE 'mo_osmo';
+
+ALTER TABLE ROUNDS ADD COLUMN
+	code		varchar(255)	NOT NULL DEFAULT '';
diff --git a/mo/db.py b/mo/db.py
index d7df8327..649ab47e 100644
--- a/mo/db.py
+++ b/mo/db.py
@@ -249,6 +249,7 @@ class Round(Base):
     seq = Column(Integer, nullable=False)
     part = Column(Integer, nullable=False)
     level = Column(Integer, nullable=False)
+    code = Column(String(255), nullable=False)
     name = Column(String(255), nullable=False)
     state = Column(Enum(RoundState, name='round_state'), nullable=False, server_default=text("'preparing'::round_state"))
     tasks_file = Column(String(255))
@@ -268,7 +269,7 @@ class Round(Base):
 
     def round_code_short(self):
         """ Pro samostatné kolo ekvivalentní s `round_code()`, pro skupinu kol společná část kódu. """
-        return f"{self.year}-{self.category}-{self.seq}"
+        return f"{self.year}-{self.category}-{self.code or self.seq}"
 
     def part_code(self):
         return chr(ord('a') + self.part - 1) if self.part > 0 else ""
-- 
GitLab