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
This commit is contained in:
Luna Mendes 2018-11-22 22:06:19 -03:00
parent 7cfa247146
commit 8d8be18633
3 changed files with 11 additions and 6 deletions

View File

@ -282,17 +282,19 @@ class Storage:
chan_type = ChannelType(channel_type) chan_type = ChannelType(channel_type)
if chan_type == ChannelType.GUILD_TEXT: if chan_type == ChannelType.GUILD_TEXT:
topic = await self.db.fetchval(""" ext_row = await self.db.fetchrow("""
SELECT topic FROM guild_text_channels SELECT topic, rate_limit_per_user
FROM guild_text_channels
WHERE id = $1 WHERE id = $1
""", row['id']) """, row['id'])
drow = dict(ext_row)
last_msg = await self.chan_last_message_str(row['id']) last_msg = await self.chan_last_message_str(row['id'])
return {**row, **{ drow['last_message_id'] = last_msg
'topic': topic,
'last_message_id': last_msg, return {**row, **drow}
}}
if chan_type == ChannelType.GUILD_VOICE: if chan_type == ChannelType.GUILD_VOICE:
vrow = await self.db.fetchrow(""" vrow = await self.db.fetchrow("""

View File

@ -0,0 +1,2 @@
ALTER TABLE guild_text_channels
ADD COLUMN rate_limit_per_user bigint DEFAULT 0;

View File

@ -356,6 +356,7 @@ CREATE TABLE IF NOT EXISTS guild_channels (
CREATE TABLE IF NOT EXISTS guild_text_channels ( CREATE TABLE IF NOT EXISTS guild_text_channels (
id bigint REFERENCES guild_channels (id) ON DELETE CASCADE, id bigint REFERENCES guild_channels (id) ON DELETE CASCADE,
topic text DEFAULT '', topic text DEFAULT '',
rate_limit_per_user bigint DEFAULT 0,
PRIMARY KEY (id) PRIMARY KEY (id)
); );