From e8e8eb4776aa2822707a3a53ca483643a6cb2aa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Setni=C4=8Dka?= <setnicka@seznam.cz> Date: Mon, 22 Mar 2021 23:38:12 +0100 Subject: [PATCH] =?UTF-8?q?DB:=20Zpr=C3=A1vi=C4=8Dky?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/db.ddl | 13 +++++++++++++ db/upgrade-20210322.sql | 16 ++++++++++++++++ mo/db.py | 15 +++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 db/upgrade-20210322.sql diff --git a/db/db.ddl b/db/db.ddl index 73a34139..7e27eb95 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 00000000..305d2e74 --- /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 4f8fa8ee..5d2c5018 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 -- GitLab