Fix sql syntax

Add database initialisation
Reorganise default theme
This commit is contained in:
Michał Gdula 2023-01-08 15:14:35 +00:00
parent 122b1760cf
commit d85ac5f103
14 changed files with 409 additions and 302 deletions

View file

@ -1,4 +1,5 @@
import time
import datetime
now = datetime.datetime.now()
import sys
import os
@ -22,7 +23,7 @@ class DBmanager():
load_dotenv(env_path)
print("### OnlyLegs Database Manager ###")
print("Connecting to database...")
print(f"{now.hour}:{now.minute}:{now.second} - Connecting to database...")
database = mysql.connector.connect(host=os.environ.get('DB_HOST'),
port=os.environ.get('DB_PORT'),
@ -41,7 +42,7 @@ class DBmanager():
record = cursor.fetchone()
print("Connected to database:", record[0])
print("Done!\n")
print(f"{now.hour}:{now.minute}:{now.second} - Done!\n")
except Error as e:
print("Error while connecting to Database!\nFull error:", e)
@ -50,14 +51,54 @@ class DBmanager():
self.database = database
def cursor(self):
return self.database.cursor()
def initialize(self):
dir = os.path.join('packages', 'tables')
if not os.path.exists(dir+'/generate.sql'):
print("Error: could not find tables directory")
print("Exiting...")
sys.exit(1)
else:
print(f"{now.hour}:{now.minute}:{now.second} - Initializing tables...")
with open(dir+'/generate.sql', 'r') as f:
sql = f.read()
cursor = self.database.cursor()
query = cursor.execute(sql, multi=True)
for res in query:
#print("Running query...")
print(f"Affected {res.rowcount} rows")
self.database.commit()
if not os.path.exists(dir+'/junctions.sql'):
print("Error: could not find junctions directory")
print("Exiting...")
sys.exit(1)
else:
print(f"{now.hour}:{now.minute}:{now.second} - Initializing junctions...")
with open(dir+'/junctions.sql', 'r') as f:
sql = f.read()
cursor = self.database.cursor()
query = cursor.execute(sql, multi=True)
for res in query:
#print("Running query...")
print(f"Affected {res.rowcount} rows")
self.database.commit()
print(f"{now.hour}:{now.minute}:{now.second} - Done!\n")
def getImage(self, id):
sql = "SELECT * FROM images WHERE id = %s"
sql = "SELECT * FROM posts WHERE id = %s"
img = (id,)
cursor = self.cursor()
cursor = self.database.cursor()
cursor.execute(sql, img)
return cursor.fetchone()

View file

@ -1,4 +1,5 @@
import time
import datetime
now = datetime.datetime.now()
import sys
import shutil
import os
@ -6,6 +7,7 @@ import os
class Sassy():
def __init__(self, theme):
print("### OnlyLegs Theme Manager ###")
print(f"{now.hour}:{now.minute}:{now.second} - Loading theme...")
try:
import sass
@ -33,7 +35,7 @@ class Sassy():
else:
print("No fonts found!")
print("Done!\n")
print(f"{now.hour}:{now.minute}:{now.second} - Done!\n")
def loadTheme (self, theme):
with open('static/css/style.css', 'w') as f:

View file

@ -1,51 +1,67 @@
CREATE IF NOT EXISTS TABLE users (
id INT(69) PRIMARY KEY AUTO_INCREMENT,
CREATE TABLE IF NOT EXISTS users (
id INT(69) NOT NULL PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(255) NOT NULL UNIQUE,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW()
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
CREATE IF NOT EXISTS TABLE posts (
CREATE TABLE IF NOT EXISTS posts (
id INT(69) PRIMARY KEY AUTO_INCREMENT,
file_name VARCHAR(255) NOT NULL UNIQUE,
author_id INT(69) NOT NULL,
description TEXT NOT NULL,
alt TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW()
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
CREATE IF NOT EXISTS TABLE groups (
CREATE TABLE IF NOT EXISTS groups (
id INT(69) PRIMARY KEY AUTO_INCREMENT,
author_id INT(69) NOT NULL,
name VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW()
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
CREATE IF NOT EXISTS TABLE permissions (
CREATE TABLE IF NOT EXISTS permissions (
id INT(69) PRIMARY KEY AUTO_INCREMENT,
user_id INT(69) NOT NULL,
admin BOOLEAN NOT NULL DEFAULT FALSE,
create_posts BOOLEAN NOT NULL DEFAULT TRUE,
updated_at TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW()
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
CREATE IF NOT EXISTS TABLE logs (
CREATE TABLE IF NOT EXISTS devices (
id INT(69) PRIMARY KEY AUTO_INCREMENT,
user_id INT(69) NOT NULL,
device_id VARCHAR(255) NOT NULL,
cookie VARCHAR(255) NOT NULL,
ip VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS tokens (
id INT(69) PRIMARY KEY AUTO_INCREMENT,
token VARCHAR(255) NOT NULL UNIQUE,
is_used BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS logs (
id INT(69) PRIMARY KEY AUTO_INCREMENT,
ip VARCHAR(255) NOT NULL,
user_id INT(69) DEFAULT NULL,
code INT(69) NOT NULL,
note TEXT DEFAULT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW()
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE IF NOT EXISTS TABLE bans (
CREATE TABLE IF NOT EXISTS bans (
id INT(69) PRIMARY KEY AUTO_INCREMENT,
ip VARCHAR(255) NOT NULL,
code INT(69) NOT NULL,
note TEXT DEFAULT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW()
);
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

View file

@ -1,4 +1,4 @@
CREATE IF NOT EXISTS TABLE group_junction (
CREATE TABLE IF NOT EXISTS group_junction (
id INT(69) PRIMARY KEY AUTO_INCREMENT,
group_id INT(69) NOT NULL,
image_id INT(69) NOT NULL