diff --git a/db/db.ddl b/db/db.ddl
index 73a341395035c1a40837c13faaa97cff85dff2ca..7e27eb955a61e9ab922a18fdf60801f9699f9e5b 100644
--- a/db/db.ddl
+++ b/db/db.ddl
@@ -107,6 +107,7 @@ CREATE TABLE rounds (
score_mode score_mode NOT NULL DEFAULT 'basic', -- mód výsledkovky
score_winner_limit int DEFAULT NULL, -- bodový limit na označení za vítěze
score_successful_limit int DEFAULT NULL, -- bodový limit na označení za úspěšného řešitele
+ has_messages boolean NOT NULL DEFAULT false, -- má zprávičky
UNIQUE (year, category, seq, part)
);
@@ -298,3 +299,15 @@ CREATE TABLE jobs (
in_file varchar(255) DEFAULT NULL,
out_file varchar(255) DEFAULT NULL
);
+
+-- Zprávičky k soutěžím
+
+CREATE TABLE messages (
+ message_id serial PRIMARY KEY,
+ round_id int NOT NULL REFERENCES rounds(round_id),
+ created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- čas publikování zprávičky
+ created_by int NOT NULL REFERENCES users(user_id), -- autor zprávičky
+ title text NOT NULL,
+ markdown text NOT NULL,
+ html text NOT NULL
+);
diff --git a/db/upgrade-20210322.sql b/db/upgrade-20210322.sql
new file mode 100644
index 0000000000000000000000000000000000000000..305d2e742cb1e149dc781f077f742fd7829c1e85
--- /dev/null
+++ b/db/upgrade-20210322.sql
@@ -0,0 +1,16 @@
+SET ROLE 'mo_osmo';
+
+-- Zprávičky k soutěžím
+
+ALTER TABLE rounds
+ ADD COLUMN has_messages boolean NOT NULL DEFAULT false; -- má zprávičky
+
+CREATE TABLE messages (
+ message_id serial PRIMARY KEY,
+ round_id int NOT NULL REFERENCES rounds(round_id),
+ created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- čas publikování zprávičky
+ created_by int NOT NULL REFERENCES users(user_id), -- autor zprávičky
+ title text NOT NULL,
+ markdown text NOT NULL,
+ html text NOT NULL
+);
diff --git a/mo/db.py b/mo/db.py
index 4f8fa8ee55caf5129dffffbc8dc78b3894229eb6..5d2c50189a63c27e52d5a01d9a96d216c8eb8e14 100644
--- a/mo/db.py
+++ b/mo/db.py
@@ -209,6 +209,7 @@ class Round(Base):
score_mode = Column(Enum(RoundScoreMode, name='score_mode'), nullable=False, server_default=text("'basic'::score_mode"))
score_winner_limit = Column(Integer)
score_successful_limit = Column(Integer)
+ has_messages = Column(Boolean, nullable=False, server_default=text("false"))
master = relationship('Round', primaryjoin='Round.master_round_id == Round.round_id', remote_side='Round.round_id', post_update=True)
@@ -592,6 +593,20 @@ class Job(Base):
user = relationship('User')
+class Message(Base):
+ __tablename__ = 'messages'
+
+ message_id = Column(Integer, primary_key=True, server_default=text("nextval('messages_message_id_seq'::regclass)"))
+ round_id = Column(Integer, ForeignKey('rounds.round_id'), nullable=False)
+ created_at = Column(DateTime(True), nullable=False, server_default=text("CURRENT_TIMESTAMP"))
+ created_by = Column(Integer, ForeignKey('users.user_id'))
+ title = Column(Text, nullable=False)
+ markdown = Column(Text, nullable=False)
+ html = Column(Text, nullable=False)
+
+ created_by_user = relationship('User')
+
+
_engine: Optional[Engine] = None
_session: Optional[Session] = None
flask_db: Any = None