File size: 864 Bytes
c5322fc
 
 
 
 
039bbf1
2cdda39
c5322fc
2cdda39
 
 
c5322fc
 
 
2cdda39
 
 
 
 
c5322fc
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# database/models.py
from datetime import datetime
import mysql.connector
from config import Config

def create_tables():
    # First, create the database if it doesn't exist
    conn = mysql.connector.connect(
        host=Config.MYSQL_HOST,
        user=Config.MYSQL_USER,
        password=Config.MYSQL_PASSWORD
    )
    cursor = conn.cursor()
    
    # Create database if it doesn't exist
    cursor.execute(f"CREATE DATABASE IF NOT EXISTS {Config.MYSQL_DB}")
    cursor.execute(f"USE {Config.MYSQL_DB}")
    
    # Create table
    cursor.execute('''
        CREATE TABLE IF NOT EXISTS chat_messages (
            id INT AUTO_INCREMENT PRIMARY KEY,
            timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
            role VARCHAR(10) NOT NULL,
            content TEXT NOT NULL
        )
    ''')
    
    conn.commit()
    cursor.close()
    conn.close()