From 9b06ea6c4554cad7a20d725ca0a007b899645ff7 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Tue, 19 Mar 2024 14:28:05 +0100 Subject: [PATCH] Bageri AB --- Migrations/0010_users.sql | 100 ++++++++++++++++++++++++++++++----- Migrations/0020_projects.sql | 9 ---- 2 files changed, 88 insertions(+), 21 deletions(-) delete mode 100644 Migrations/0020_projects.sql diff --git a/Migrations/0010_users.sql b/Migrations/0010_users.sql index 5c9d329..3822720 100644 --- a/Migrations/0010_users.sql +++ b/Migrations/0010_users.sql @@ -1,14 +1,90 @@ --- Id is a surrogate key for in ternal use --- userId is what is used for external id --- username is what is used for login --- password is the hashed password -CREATE TABLE IF NOT EXISTS users ( - id INTEGER PRIMARY KEY, - userId TEXT DEFAULT (HEX(RANDOMBLOB(4))) NOT NULL UNIQUE, - username VARCHAR(255) NOT NULL UNIQUE, - password VARCHAR(255) NOT NULL +CREATE TABLE IF NOT EXISTS Customers ( + CustomerID int PRIMARY KEY, + Name varchar(100), + Address varchar(255) ); --- Users are commonly searched by username and userId -CREATE INDEX IF NOT EXISTS users_username_index ON users (username); -CREATE INDEX IF NOT EXISTS users_userId_index ON users (userId); \ No newline at end of file +CREATE TABLE IF NOT EXISTS Products ( + ProductID int PRIMARY KEY, + Name varchar(100) +); + +CREATE TABLE IF NOT EXISTS Recipes ( + RecipeName varchat(100), + RecipeYear Year, + ingrediences int, + ProductID int, + PRIMARY KEY (RecipeName, RecipeYear) + FOREIGN KEY (ingrediences) REFERENCES ingredience(IngredienceID) +); + +CREATE TABLE IF NOT EXISTS ingredience ( + IngredienceID int PRIMARY KEY, + RawMaterialName varchar(100), + amount int, + unit varchar(50) +); + +CREATE TABLE IF NOT EXISTS RawMaterials ( + RawMaterialName varchar(100) PRIMARY KEY, + Quantity int, + LastDeliveryDateTime datetime +); + +CREATE TABLE IF NOT EXISTS PalletsProduced ( + PalletID int PRIMARY KEY, + ProductID int, + ProductionDateTime datetime +); + +CREATE TABLE IF NOT EXISTS PalletsDelivered ( + DeliveredID int PRIMARY KEY, + PalletID int, + DeliveryDateTime datetime +); + +CREATE TABLE IF NOT EXISTS Truck ( + truckId int PRIMARY KEY, + capacity int, + Pallet int +); + +CREATE TABLE IF NOT EXISTS loadingBill ( + LoadingbillID int PRIMARY KEY, + adress varchar(100), + customer varchar(100), + truckID int +); + +CREATE TABLE IF NOT EXISTS Orders ( + OrderID int PRIMARY KEY, + CustomerID int, + ProductID int, + Quantity int, + OrderDateTime datetime +); + +CREATE TABLE IF NOT EXISTS BlockedProducts ( + BlockedProductID int PRIMARY KEY, + ProductID int, + BlockedDateTime datetime +); + +CREATE TABLE IF NOT EXISTS PalletTraceability ( + TraceID int PRIMARY KEY, + location varchar(100), + locationdate datetime, + PalletID int +); + + +-- ALTER TABLE Recipes ADD FOREIGN KEY (ProductID) REFERENCES Products (ProductID); +-- ALTER TABLE ingredience ADD FOREIGN KEY (RawMaterialName) REFERENCES RawMaterials (RawMaterialName); +-- ALTER TABLE PalletsProduced ADD FOREIGN KEY (ProductID) REFERENCES Products (ProductID); +-- ALTER TABLE PalletsDelivered ADD FOREIGN KEY (PalletID) REFERENCES PalletsProduced (PalletID); +-- ALTER TABLE PalletsDelivered ADD FOREIGN KEY (DeliveredID) REFERENCES Truck (Pallet); +-- ALTER TABLE loadingBill ADD FOREIGN KEY (truckID) REFERENCES Truck (truckId); +-- ALTER TABLE Orders ADD FOREIGN KEY (CustomerID) REFERENCES Customers (CustomerID); +-- ALTER TABLE Orders ADD FOREIGN KEY (ProductID) REFERENCES Products (ProductID); +-- ALTER TABLE BlockedProducts ADD FOREIGN KEY (ProductID) REFERENCES Products (ProductID); +-- ALTER TABLE PalletTraceability ADD FOREIGN KEY (PalletID) REFERENCES PalletsProduced (PalletID); diff --git a/Migrations/0020_projects.sql b/Migrations/0020_projects.sql deleted file mode 100644 index 58d8e97..0000000 --- a/Migrations/0020_projects.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE TABLE IF NOT EXISTS projects ( - id INTEGER PRIMARY KEY, - name VARCHAR(255) NOT NULL UNIQUE, - description TEXT NOT NULL, - owner_user_id INTEGER NOT NULL, - FOREIGN KEY (owner_user_id) REFERENCES users (id) -); - -CREATE INDEX IF NOT EXISTS projects_user_id_index ON projects (owner_user_id); \ No newline at end of file