File size: 998 Bytes
fa8bc8c
 
418c329
 
fa8bc8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
418c329
fa8bc8c
 
 
418c329
fa8bc8c
 
 
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
33
34
35
36
37
38
# 📄 File: init_db.py

import sqlite3

# Name of the database file
DB_FILE = "chat_history.db"

def init_db():
    # Connect to the database (creates file if it doesn't exist)
    conn = sqlite3.connect(DB_FILE)
    c = conn.cursor()

    # ✅ Create 'chat' table: stores individual messages in a session
    c.execute('''

        CREATE TABLE IF NOT EXISTS chat (

            id INTEGER PRIMARY KEY AUTOINCREMENT,

            session_id TEXT NOT NULL,

            timestamp TEXT NOT NULL,

            user TEXT,

            bot TEXT

        )

    ''')

    # ✅ Create 'sessions' table: stores session metadata
    c.execute('''

        CREATE TABLE IF NOT EXISTS sessions (

            session_id TEXT PRIMARY KEY,

            created_at TEXT NOT NULL

        )

    ''')

    conn.commit()
    conn.close()
    print("✅ Database initialized successfully.")

# Run the function if this script is executed directly
if __name__ == "__main__":
    init_db()