From ad803b5dea85481991e93841d4e7f4f4525b8793 Mon Sep 17 00:00:00 2001
From: Martin Mares <mj@ucw.cz>
Date: Fri, 29 Sep 2023 23:06:45 +0200
Subject: [PATCH] =?UTF-8?q?DB:=20Rok=20narozen=C3=AD=20nen=C3=AD=20povinn?=
 =?UTF-8?q?=C3=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 db/db.ddl               | 2 +-
 db/upgrade-20230929.sql | 4 ++++
 mo/db.py                | 2 +-
 3 files changed, 6 insertions(+), 2 deletions(-)
 create mode 100644 db/upgrade-20230929.sql

diff --git a/db/db.ddl b/db/db.ddl
index 7727df20..a7c33b39 100644
--- a/db/db.ddl
+++ b/db/db.ddl
@@ -179,7 +179,7 @@ CREATE TABLE participants (
 	user_id		int		NOT NULL REFERENCES users(user_id),
 	year		int		NOT NULL,			-- ročník MO
 	school		int		NOT NULL REFERENCES places(place_id),
-	birth_year	int		NOT NULL,
+	birth_year	int,
 	grade		varchar(20)	NOT NULL,			-- třída ve tvaru "X/Y"
 	registered_on	timestamp with time zone	DEFAULT NULL,	-- kdy se účastník přihlásil (NULL, pokud ho přihlásil organizátor)
 	PRIMARY KEY (user_id, year)
diff --git a/db/upgrade-20230929.sql b/db/upgrade-20230929.sql
new file mode 100644
index 00000000..576c8e28
--- /dev/null
+++ b/db/upgrade-20230929.sql
@@ -0,0 +1,4 @@
+SET ROLE 'mo_osmo';
+
+ALTER TABLE participants
+	ALTER COLUMN birth_year DROP NOT NULL;
diff --git a/mo/db.py b/mo/db.py
index 33f4156b..434f3559 100644
--- a/mo/db.py
+++ b/mo/db.py
@@ -541,7 +541,7 @@ class Participant(Base):
     user_id = Column(Integer, ForeignKey('users.user_id'), primary_key=True, nullable=False)
     year = Column(Integer, primary_key=True, nullable=False)
     school = Column(Integer, ForeignKey('places.place_id'), nullable=False)
-    birth_year = Column(Integer, nullable=False)
+    birth_year = Column(Integer, nullable=True)
     grade = Column(String(20), nullable=False)
     registered_on = Column(DateTime(True))
 
-- 
GitLab