nikhildsst commited on
Commit
2cdda39
·
verified ·
1 Parent(s): f036750

Update database/models.py

Browse files
Files changed (1) hide show
  1. database/models.py +9 -10
database/models.py CHANGED
@@ -3,19 +3,20 @@ from datetime import datetime
3
  import mysql.connector
4
  from config import Config
5
 
6
-
7
  def create_tables():
 
8
  conn = mysql.connector.connect(
9
- host='127.0.0.1',
10
- port=3306, # explicitly specify port
11
- user='root',
12
- password='your_password', # make sure this is your actual MySQL root password
13
- database='ragchatbot',
14
- auth_plugin='mysql_native_password' # explicitly specify auth method
15
  )
16
-
17
  cursor = conn.cursor()
18
 
 
 
 
 
 
19
  cursor.execute('''
20
  CREATE TABLE IF NOT EXISTS chat_messages (
21
  id INT AUTO_INCREMENT PRIMARY KEY,
@@ -28,5 +29,3 @@ def create_tables():
28
  conn.commit()
29
  cursor.close()
30
  conn.close()
31
-
32
-
 
3
  import mysql.connector
4
  from config import Config
5
 
 
6
  def create_tables():
7
+ # First, create the database if it doesn't exist
8
  conn = mysql.connector.connect(
9
+ host=Config.MYSQL_HOST,
10
+ user=Config.MYSQL_USER,
11
+ password=Config.MYSQL_PASSWORD
 
 
 
12
  )
 
13
  cursor = conn.cursor()
14
 
15
+ # Create database if it doesn't exist
16
+ cursor.execute(f"CREATE DATABASE IF NOT EXISTS {Config.MYSQL_DB}")
17
+ cursor.execute(f"USE {Config.MYSQL_DB}")
18
+
19
+ # Create table
20
  cursor.execute('''
21
  CREATE TABLE IF NOT EXISTS chat_messages (
22
  id INT AUTO_INCREMENT PRIMARY KEY,
 
29
  conn.commit()
30
  cursor.close()
31
  conn.close()