gems: Generalise gem transaction table.
Updates gem audit table for more generality. Fixes issue with `Row._refresh()`. Data migration v11 -> v12. Remove `set_gems` (not needed due to gem module refactor).
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
CONFIG_FILE = "config/bot.conf"
|
||||
DATA_VERSION = 11
|
||||
DATA_VERSION = 12
|
||||
|
||||
@@ -123,19 +123,6 @@ def get_member_rank(guildid, userid, untracked):
|
||||
return curs.fetchone() or (None, None)
|
||||
|
||||
|
||||
@user_config.save_query
|
||||
def set_gems(userid, amount):
|
||||
with user_config.conn as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"UPDATE user_config SET gems = %s WHERE userid = %s RETURNING *",
|
||||
(amount, userid)
|
||||
)
|
||||
data = cursor.fetchone()
|
||||
if data:
|
||||
return user_config._make_rows(data)[0]
|
||||
|
||||
|
||||
global_guild_blacklist = Table('global_guild_blacklist')
|
||||
global_user_blacklist = Table('global_user_blacklist')
|
||||
ignored_members = Table('ignored_members')
|
||||
|
||||
@@ -149,7 +149,7 @@ class Row:
|
||||
self._pending = None
|
||||
|
||||
def _refresh(self):
|
||||
row = self.table.select_one_where(self.table.dict_from_id(self.rowid))
|
||||
row = self.table.select_one_where(**self.table.dict_from_id(self.rowid))
|
||||
if not row:
|
||||
raise ValueError("Refreshing a {} which no longer exists!".format(type(self).__name__))
|
||||
self.data = row
|
||||
|
||||
27
data/migration/v11-v12/migration.sql
Normal file
27
data/migration/v11-v12/migration.sql
Normal file
@@ -0,0 +1,27 @@
|
||||
-- Add gem support
|
||||
ALTER TABLE user_config ADD COLUMN gems INTEGER DEFAULT 0;
|
||||
|
||||
-- LionGem audit log {{{
|
||||
CREATE TYPE GemTransactionType AS ENUM (
|
||||
'ADMIN',
|
||||
'GIFT',
|
||||
'PURCHASE',
|
||||
'AUTOMATIC'
|
||||
);
|
||||
|
||||
CREATE TABLE gem_transactions(
|
||||
transactionid SERIAL PRIMARY KEY,
|
||||
transaction_type GemTransactionType NOT NULL,
|
||||
actorid BIGINT NOT NULL,
|
||||
from_account BIGINT,
|
||||
to_account BIGINT,
|
||||
amount INTEGER NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
note TEXT,
|
||||
reference TEXT,
|
||||
_timestamp TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
CREATE INDEX gem_transactions_from ON gem_transactions (from_account);
|
||||
-- }}}
|
||||
|
||||
INSERT INTO VersionHistory (version, author) VALUES (12, 'v11-v12 migration');
|
||||
@@ -4,7 +4,7 @@ CREATE TABLE VersionHistory(
|
||||
time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
author TEXT
|
||||
);
|
||||
INSERT INTO VersionHistory (version, author) VALUES (11, 'Initial Creation');
|
||||
INSERT INTO VersionHistory (version, author) VALUES (12, 'Initial Creation');
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION update_timestamp_column()
|
||||
@@ -823,17 +823,26 @@ CREATE TABLE sponsor_guild_whitelist(
|
||||
-- }}}
|
||||
|
||||
-- LionGem audit log {{{
|
||||
CREATE TYPE GemTransactionType AS ENUM (
|
||||
'ADMIN',
|
||||
'GIFT',
|
||||
'PURCHASE',
|
||||
'AUTOMATIC'
|
||||
);
|
||||
|
||||
CREATE TABLE gem_transactions(
|
||||
transactionid SERIAL PRIMARY KEY,
|
||||
transaction_type GemTransactionType NOT NULL,
|
||||
actorid BIGINT NOT NULL,
|
||||
targetid BIGINT NOT NULL,
|
||||
from_account BIGINT,
|
||||
to_account BIGINT,
|
||||
amount INTEGER NOT NULL,
|
||||
total INTEGER NOT NULL,
|
||||
reason TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
note TEXT,
|
||||
gift BOOLEAN DEFAULT FALSE,
|
||||
reference TEXT,
|
||||
_timestamp TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
CREATE INDEX gem_transactions_from ON gem_transactions (from_account);
|
||||
-- }}}
|
||||
|
||||
-- vim: set fdm=marker:
|
||||
|
||||
Reference in New Issue
Block a user