migration_1.py 801 B

1234567891011121314151617181920212223242526272829303132
  1. # Initial migration, token usage logging
  2. from datetime import datetime
  3. def migration(conn):
  4. with conn.cursor() as cursor:
  5. cursor.execute(
  6. """
  7. CREATE TABLE IF NOT EXISTS token_usage (
  8. message_id TEXT PRIMARY KEY,
  9. room_id TEXT NOT NULL,
  10. tokens INTEGER NOT NULL,
  11. timestamp TIMESTAMP NOT NULL
  12. )
  13. """
  14. )
  15. cursor.execute(
  16. """
  17. CREATE TABLE IF NOT EXISTS migrations (
  18. id INTEGER NOT NULL,
  19. timestamp TIMESTAMP NOT NULL
  20. )
  21. """
  22. )
  23. cursor.execute(
  24. "INSERT INTO migrations (id, timestamp) VALUES (1, ?)",
  25. (datetime.now(),)
  26. )
  27. conn.commit()