Created
June 7, 2023 15:00
-
-
Save motleydev/d4d442e21f8872ab2b77f66771f2752f to your computer and use it in GitHub Desktop.
TeamSystemResources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Create the "drivers" table to store information about the gig economy drivers | |
CREATE TABLE public.drivers ( | |
driver_id SERIAL PRIMARY KEY, | |
name VARCHAR(100) NOT NULL, | |
phone_number VARCHAR(20) NOT NULL, | |
email VARCHAR(100) NOT NULL, | |
active BOOLEAN DEFAULT true, | |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | |
); | |
-- Create the "chocolates" table to store information about the available Ferrero chocolates | |
CREATE TABLE public.chocolates ( | |
chocolate_id SERIAL PRIMARY KEY, | |
name VARCHAR(100) NOT NULL, | |
description TEXT, | |
price NUMERIC(10, 2) NOT NULL, | |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | |
); | |
-- Create the "orders" table to store information about customer orders | |
CREATE TABLE public.orders ( | |
order_id SERIAL PRIMARY KEY, | |
customer_name VARCHAR(100) NOT NULL, | |
customer_phone_number VARCHAR(20) NOT NULL, | |
customer_address TEXT NOT NULL, | |
total_amount NUMERIC(10, 2) NOT NULL, | |
order_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | |
delivery_date TIMESTAMP, | |
driver_id INT REFERENCES public.drivers(driver_id), | |
delivered BOOLEAN DEFAULT false, | |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | |
); | |
-- Create the "order_items" table to store the details of each chocolate item in an order | |
CREATE TABLE public.order_items ( | |
item_id SERIAL PRIMARY KEY, | |
order_id INT REFERENCES public.orders(order_id), | |
chocolate_id INT REFERENCES public.chocolates(chocolate_id), | |
quantity INT NOT NULL, | |
price NUMERIC(10, 2) NOT NULL | |
); | |
-- Create the "depots" table to store information about warehouse depots | |
CREATE TABLE public.depots ( | |
depot_id SERIAL PRIMARY KEY, | |
name VARCHAR(100) NOT NULL, | |
location TEXT NOT NULL, | |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | |
); | |
-- Create the "inventory" table to track the chocolate inventory in depots | |
CREATE TABLE public.inventory ( | |
inventory_id SERIAL PRIMARY KEY, | |
depot_id INT REFERENCES public.depots(depot_id), | |
chocolate_id INT REFERENCES public.chocolates(chocolate_id), | |
quantity INT NOT NULL, | |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | |
); | |
-- Create the "delivery" table to track the delivery of orders | |
CREATE TABLE public.delivery ( | |
delivery_id SERIAL PRIMARY KEY, | |
order_id INT REFERENCES public.orders(order_id), | |
driver_id INT REFERENCES public.drivers(driver_id), | |
depot_id INT REFERENCES public.depots(depot_id), | |
delivery_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | |
); |
Author
motleydev
commented
Jun 7, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment