From 8d8be18633fc3f3b67524e4b484f7fb830152e44 Mon Sep 17 00:00:00 2001 From: Luna Mendes Date: Thu, 22 Nov 2018 22:06:19 -0300 Subject: [PATCH] storage: add rate_limit_per_user fetching the rate_limit_per_user field has been on schema.CHAN_UPDATE for a while but the database didn't have the column. - migration.scripts: add 7_text_channels_rate_limit_per_user.sql - schema.sql: add guild_text_channels.rate_limit_per_user --- litecord/storage.py | 14 ++++++++------ .../7_text_channels_rate_limit_per_user.sql | 2 ++ schema.sql | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 manage/cmd/migration/scripts/7_text_channels_rate_limit_per_user.sql diff --git a/litecord/storage.py b/litecord/storage.py index 0bb1cce..29cf405 100644 --- a/litecord/storage.py +++ b/litecord/storage.py @@ -282,17 +282,19 @@ class Storage: chan_type = ChannelType(channel_type) if chan_type == ChannelType.GUILD_TEXT: - topic = await self.db.fetchval(""" - SELECT topic FROM guild_text_channels + ext_row = await self.db.fetchrow(""" + SELECT topic, rate_limit_per_user + FROM guild_text_channels WHERE id = $1 """, row['id']) + drow = dict(ext_row) + last_msg = await self.chan_last_message_str(row['id']) - return {**row, **{ - 'topic': topic, - 'last_message_id': last_msg, - }} + drow['last_message_id'] = last_msg + + return {**row, **drow} if chan_type == ChannelType.GUILD_VOICE: vrow = await self.db.fetchrow(""" diff --git a/manage/cmd/migration/scripts/7_text_channels_rate_limit_per_user.sql b/manage/cmd/migration/scripts/7_text_channels_rate_limit_per_user.sql new file mode 100644 index 0000000..4976086 --- /dev/null +++ b/manage/cmd/migration/scripts/7_text_channels_rate_limit_per_user.sql @@ -0,0 +1,2 @@ +ALTER TABLE guild_text_channels +ADD COLUMN rate_limit_per_user bigint DEFAULT 0; diff --git a/schema.sql b/schema.sql index cfdf955..b912fe3 100644 --- a/schema.sql +++ b/schema.sql @@ -356,6 +356,7 @@ CREATE TABLE IF NOT EXISTS guild_channels ( CREATE TABLE IF NOT EXISTS guild_text_channels ( id bigint REFERENCES guild_channels (id) ON DELETE CASCADE, topic text DEFAULT '', + rate_limit_per_user bigint DEFAULT 0, PRIMARY KEY (id) );