mirror of
https://github.com/alterware/aw-bot.git
synced 2025-10-26 22:16:58 +00:00
feat: migrate DB table
This commit is contained in:
@@ -59,28 +59,28 @@ def remove_pattern(pattern_id: int):
|
||||
conn.close()
|
||||
|
||||
|
||||
def migrate_users_with_role(user_id: int, role_id: int):
|
||||
def migrate_users_with_role(user_id: int, role_id: int, user_name: str):
|
||||
"""Migrates existing users with the role to the new table."""
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute(
|
||||
"INSERT OR IGNORE INTO user_roles (user_id, role_id, date_assigned) VALUES (?, ?, ?)",
|
||||
(user_id, role_id, aware_utcnow().isoformat()),
|
||||
"INSERT OR IGNORE INTO user_roles (user_id, role_id, date_assigned, user_name) VALUES (?, ?, ?, ?)",
|
||||
(user_id, role_id, aware_utcnow().isoformat(), user_name),
|
||||
)
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def add_user_to_role(user_id: int, role_id: int):
|
||||
def add_user_to_role(user_id: int, role_id: int, user_name: str):
|
||||
"""Adds a new user when they receive the role."""
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute(
|
||||
"INSERT OR REPLACE INTO user_roles (user_id, role_id, date_assigned) VALUES (?, ?, ?)",
|
||||
(user_id, role_id, aware_utcnow().isoformat()),
|
||||
"INSERT OR REPLACE INTO user_roles (user_id, role_id, date_assigned, user_name) VALUES (?, ?, ?, ?)",
|
||||
(user_id, role_id, aware_utcnow().isoformat(), user_name),
|
||||
)
|
||||
|
||||
conn.commit()
|
||||
|
||||
@@ -7,5 +7,6 @@ CREATE TABLE IF NOT EXISTS message_patterns (
|
||||
CREATE TABLE IF NOT EXISTS user_roles (
|
||||
user_id INTEGER PRIMARY KEY,
|
||||
role_id INTEGER NOT NULL,
|
||||
date_assigned TEXT
|
||||
date_assigned TEXT,
|
||||
user_name TEXT
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user