Bageri AB
This commit is contained in:
parent
b5f2d425bd
commit
9b06ea6c45
2 changed files with 88 additions and 21 deletions
|
@ -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);
|
||||
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);
|
||||
|
|
|
@ -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);
|
Loading…
Reference in a new issue