fix: DB table creation with server
All checks were successful
Build Docker / Build SLDs Image (push) Successful in 18s
Build Docker / Build Main Image (push) Successful in 19s

This commit is contained in:
Nathan Woodburn 2023-11-08 19:11:55 +11:00
parent dd50a175e6
commit 88b1ea53f5
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 40 additions and 2 deletions

3
db.py
View File

@ -27,8 +27,7 @@ def check_tables():
token VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
)
""")
""")
cursor.close()
connection.close()

39
sites/db.py Normal file
View File

@ -0,0 +1,39 @@
import mysql.connector
import os
import dotenv
dotenv.load_dotenv()
# Database connection
dbargs = {
'host':os.getenv('DB_HOST'),
'user':os.getenv('DB_USER'),
'password':os.getenv('DB_PASSWORD'),
'database':os.getenv('DB_NAME')
}
def check_tables():
connection = mysql.connector.connect(**dbargs)
cursor = connection.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS site (
id INT(11) NOT NULL AUTO_INCREMENT,
domain VARCHAR(255) NOT NULL,
data VARCHAR(2048) NOT NULL,
PRIMARY KEY (id)
)
""")
cursor.close()
connection.close()
def get_site(domain):
connection = mysql.connector.connect(**dbargs)
cursor = connection.cursor()
cursor.execute("""
SELECT * FROM site WHERE domain = %s
""", (domain,))
site = cursor.fetchall()
cursor.close()
connection.close()
return site