CrustyCookiesAPI/app/Migrations/0010-tables.sql

88 lines
2.2 KiB
SQL

CREATE TABLE IF NOT EXISTS Customers (
CustomerID int PRIMARY KEY,
Name varchar(100),
Address varchar(255)
);
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),
FOREIGN KEY (ProductID) REFERENCES Products(ProductID)
);
CREATE TABLE IF NOT EXISTS ingredience (
IngredienceID int PRIMARY KEY,
RawMaterialName varchar(100),
amount int,
unit varchar(50),
FOREIGN KEY (RawMaterialName) REFERENCES RawMaterials(RawMaterialName)
);
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,
FOREIGN KEY (ProductID) REFERENCES Products (ProductID)
);
CREATE TABLE IF NOT EXISTS PalletsDelivered (
DeliveredID int PRIMARY KEY,
PalletID int,
DeliveryDateTime datetime,
FOREIGN KEY (PalletID) REFERENCES PalletsProduced (PalletID),
FOREIGN KEY (DeliveredID) REFERENCES Truck (Pallet)
);
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,
FOREIGN KEY (truckID) REFERENCES Truck (truckId)
);
CREATE TABLE IF NOT EXISTS Orders (
OrderID int PRIMARY KEY,
CustomerID int,
ProductID int,
Quantity int,
OrderDateTime datetime,
FOREIGN KEY (CustomerID) REFERENCES Customers (CustomerID),
FOREIGN KEY (ProductID) REFERENCES Products (ProductID)
);
CREATE TABLE IF NOT EXISTS BlockedProducts (
BlockedProductID int PRIMARY KEY,
ProductID int,
BlockedDateTime datetime,
FOREIGN KEY (ProductID) REFERENCES Products (ProductID)
);
CREATE TABLE IF NOT EXISTS PalletTraceability (
TraceID int PRIMARY KEY,
location varchar(100),
locationdate datetime,
PalletID int,
FOREIGN KEY (PalletID) REFERENCES PalletsProduced (PalletID)
);