matrix-rssbot/migrations/migration_6.py
Kumi 5997ee8ab1
Implement chat message classification
!gptbot roomsettings command
Permit custom commands (!gptbot custom ...)
2023-05-01 08:12:50 +00:00

32 lines
No EOL
908 B
Python

# Migration to drop primary key constraint from token_usage table
from datetime import datetime
def migration(conn):
with conn.cursor() as cursor:
cursor.execute(
"""
CREATE TABLE token_usage_temp (
message_id TEXT NOT NULL,
room_id TEXT NOT NULL,
api TEXT NOT NULL,
tokens INTEGER NOT NULL,
timestamp TIMESTAMP NOT NULL
)
"""
)
cursor.execute(
"INSERT INTO token_usage_temp SELECT message_id, room_id, api, tokens, timestamp FROM token_usage"
)
cursor.execute("DROP TABLE token_usage")
cursor.execute("ALTER TABLE token_usage_temp RENAME TO token_usage")
cursor.execute(
"INSERT INTO migrations (id, timestamp) VALUES (6, ?)",
(datetime.now(),)
)
conn.commit()