Eh, kinda working

This commit is contained in:
2026-02-09 14:08:41 -06:00
parent 377b6b496b
commit 6f693dc19c
7 changed files with 384 additions and 0 deletions

43
db.py Normal file
View File

@@ -0,0 +1,43 @@
import mysql.connector
import os
def get_db():
return mysql.connector.connect(
host=os.getenv("MYSQL_HOST"),
user=os.getenv("MYSQL_USER"),
password=os.getenv("MYSQL_PASSWORD"),
database=os.getenv("MYSQL_DATABASE"),
autocommit=True
)
def init_db():
db = get_db()
cur = db.cursor()
cur.execute("""
CREATE TABLE IF NOT EXISTS users (
discord_id VARCHAR(32) PRIMARY KEY,
val_tag VARCHAR(32) NOT NULL,
rank VARCHAR(32) NOT NULL,
rr INT DEFAULT 0,
kills INT DEFAULT 0,
deaths INT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
""")
cur.execute("""
CREATE TABLE IF NOT EXISTS workouts (
discord_id VARCHAR(32),
workout VARCHAR(32),
amount INT DEFAULT 0,
PRIMARY KEY (discord_id, workout),
FOREIGN KEY (discord_id)
REFERENCES users(discord_id)
ON DELETE CASCADE
)
""")
cur.close()
db.close()
print("✅ Database ready")