Updated line endings to be in line with UNIX style
This commit is contained in:
@ -1,51 +1,51 @@
|
||||
import sqlite3
|
||||
import os
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.path.append(os.getcwd())
|
||||
|
||||
from utils.file_utils import create_directory, remove_file
|
||||
|
||||
|
||||
def create_connection(path: str, filename: str):
|
||||
""" create a database connection to a SQLite database """
|
||||
conn = None
|
||||
try:
|
||||
# Make the directory for the file to go into
|
||||
create_directory(path)
|
||||
|
||||
print("Opening Database file and ensuring table integrity")
|
||||
conn = sqlite3.connect(path + filename)
|
||||
|
||||
print("Database file open")
|
||||
# Execute creation scripts
|
||||
sql = open("scripts/create_tables.sql", "r")
|
||||
conn.executescript(sql.read())
|
||||
|
||||
print("Table creation complete")
|
||||
|
||||
# Populate with test data if we are in Test Mode
|
||||
if os.environ.get("ENVIRON") == "test":
|
||||
sql = open("scripts/test_data.sql", "r")
|
||||
conn.executescript(sql.read())
|
||||
|
||||
except sqlite3.Error as e:
|
||||
print(e)
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
|
||||
# Ensure a directory is created given a path to it
|
||||
dir = r"./data/"
|
||||
db_name = r"wmgzon.db"
|
||||
|
||||
# Check for test environ
|
||||
if os.environ.get("ENVIRON") == "test":
|
||||
# Remove the original test database
|
||||
print("TEST ENVIRONMENT ACTIVE")
|
||||
db_name = "test_" + db_name
|
||||
remove_file(dir + db_name)
|
||||
|
||||
create_connection(dir, db_name)
|
||||
import sqlite3
|
||||
import os
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.path.append(os.getcwd())
|
||||
|
||||
from utils.file_utils import create_directory, remove_file
|
||||
|
||||
|
||||
def create_connection(path: str, filename: str):
|
||||
""" create a database connection to a SQLite database """
|
||||
conn = None
|
||||
try:
|
||||
# Make the directory for the file to go into
|
||||
create_directory(path)
|
||||
|
||||
print("Opening Database file and ensuring table integrity")
|
||||
conn = sqlite3.connect(path + filename)
|
||||
|
||||
print("Database file open")
|
||||
# Execute creation scripts
|
||||
sql = open("scripts/create_tables.sql", "r")
|
||||
conn.executescript(sql.read())
|
||||
|
||||
print("Table creation complete")
|
||||
|
||||
# Populate with test data if we are in Test Mode
|
||||
if os.environ.get("ENVIRON") == "test":
|
||||
sql = open("scripts/test_data.sql", "r")
|
||||
conn.executescript(sql.read())
|
||||
|
||||
except sqlite3.Error as e:
|
||||
print(e)
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
|
||||
# Ensure a directory is created given a path to it
|
||||
dir = r"./data/"
|
||||
db_name = r"wmgzon.db"
|
||||
|
||||
# Check for test environ
|
||||
if os.environ.get("ENVIRON") == "test":
|
||||
# Remove the original test database
|
||||
print("TEST ENVIRONMENT ACTIVE")
|
||||
db_name = "test_" + db_name
|
||||
remove_file(dir + db_name)
|
||||
|
||||
create_connection(dir, db_name)
|
||||
|
@ -1,56 +1,56 @@
|
||||
CREATE TABLE IF NOT EXISTS Users (
|
||||
id INTEGER PRIMARY KEY,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
password TEXT NOT NULL,
|
||||
first_name TEXT NOT NULL,
|
||||
last_name TEXT NOT NULL,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
phone TEXT NOT NULL,
|
||||
role TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Categories (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
INSERT INTO Categories (name) VALUES ("Car Parts");
|
||||
INSERT INTO Categories (name) VALUES ("Animals");
|
||||
INSERT INTO Categories (name) VALUES ("Sports");
|
||||
INSERT INTO Categories (name) VALUES ("Books");
|
||||
INSERT INTO Categories (name) VALUES ("Phones");
|
||||
INSERT INTO Categories (name) VALUES ("Music");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Products (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
image TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
cost DECIMAL NOT NULL,
|
||||
sellerID INTEGER NOT NULL
|
||||
REFERENCES Users (id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION,
|
||||
categoryID INTEGER NOT NULL
|
||||
REFERENCES Categories (id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION,
|
||||
postedDate TIMESTAMP,
|
||||
quantityAvailable INTEGER DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Orders (
|
||||
id INTEGER PRIMARY KEY,
|
||||
sellerID TEXT NOT NULL
|
||||
REFERENCES Users (id)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
total DECIMAL NOT NULL,
|
||||
buyerID INTEGER NOT NULL
|
||||
REFERENCES Users (id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION,
|
||||
orderDate DATE NOT NULL
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Users (
|
||||
id INTEGER PRIMARY KEY,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
password TEXT NOT NULL,
|
||||
first_name TEXT NOT NULL,
|
||||
last_name TEXT NOT NULL,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
phone TEXT NOT NULL,
|
||||
role TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Categories (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
INSERT INTO Categories (name) VALUES ("Car Parts");
|
||||
INSERT INTO Categories (name) VALUES ("Animals");
|
||||
INSERT INTO Categories (name) VALUES ("Sports");
|
||||
INSERT INTO Categories (name) VALUES ("Books");
|
||||
INSERT INTO Categories (name) VALUES ("Phones");
|
||||
INSERT INTO Categories (name) VALUES ("Music");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Products (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
image TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
cost DECIMAL NOT NULL,
|
||||
sellerID INTEGER NOT NULL
|
||||
REFERENCES Users (id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION,
|
||||
categoryID INTEGER NOT NULL
|
||||
REFERENCES Categories (id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION,
|
||||
postedDate TIMESTAMP,
|
||||
quantityAvailable INTEGER DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Orders (
|
||||
id INTEGER PRIMARY KEY,
|
||||
sellerID TEXT NOT NULL
|
||||
REFERENCES Users (id)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
total DECIMAL NOT NULL,
|
||||
buyerID INTEGER NOT NULL
|
||||
REFERENCES Users (id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION,
|
||||
orderDate DATE NOT NULL
|
||||
);
|
||||
|
||||
|
||||
|
@ -1,37 +1,37 @@
|
||||
INSERT INTO Users (first_name, last_name, username, email, phone, password, role) VALUES ("Luke", "Else", "lukejelse04", "test@test.com", "07498 289321", "test213", "Customer");
|
||||
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 2);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 2);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 3);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 6);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 6);
|
||||
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 2);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 2);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 3);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 6);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 6);
|
||||
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 2);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 2);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 3);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 6);
|
||||
INSERT INTO Users (first_name, last_name, username, email, phone, password, role) VALUES ("Luke", "Else", "lukejelse04", "test@test.com", "07498 289321", "test213", "Customer");
|
||||
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 2);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 2);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 3);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 6);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 6);
|
||||
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 2);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 2);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 3);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 6);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 6);
|
||||
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 1);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 2);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 2);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 3);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 4);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 6);
|
||||
INSERT INTO Products (name, image, description, cost, sellerID, categoryID) VALUES ("test", "brake-disks.png", "this is a product", 20.99, 1, 6);
|
Reference in New Issue
Block a user