From 0416a1d3daee399de370da56bb3d617e9de212ce Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Fri, 3 May 2024 08:16:21 +0200 Subject: [PATCH] Correcting sql, work on tables --- app/Migrations/create-schema.sql | 14 ++++++-------- app/Migrations/initial-data.sql | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/Migrations/create-schema.sql b/app/Migrations/create-schema.sql index 112dfbc..483694f 100644 --- a/app/Migrations/create-schema.sql +++ b/app/Migrations/create-schema.sql @@ -7,18 +7,16 @@ CREATE TABLE IF NOT EXISTS customers ( customer_id int PRIMARY KEY, customer_name varchar(100), customer_address varchar(255) - -- ...Perhaps more columns ); -- Orders from customers. -- Keep in mind that the delivery_date may be NULL -CREATE TABLE IF NOT EXISTS Orders ( +CREATE TABLE IF NOT EXISTS orders ( order_id int PRIMARY KEY, customer_id int, - order_date date DEFAULT NOW(), + order_date date DEFAULT NOW, delivery_date date, -- Set when the order hits the truck FOREIGN KEY (customer_id) REFERENCES customers(customer_id) - -- ...Perhaps more columns ); -------------------------------------------- @@ -28,7 +26,7 @@ CREATE TABLE IF NOT EXISTS Orders ( -- Recipes for all the cookies (essentially a list of cookies) CREATE TABLE IF NOT EXISTS recipes ( recipe_id int PRIMARY KEY, - recipe_name varchar(100), -- Cookie name + recipe_name varchar(100) -- Cookie name ); -- "The company has a raw materials warehouse in which @@ -40,7 +38,7 @@ CREATE TABLE IF NOT EXISTS ingredients ( ingredient_id int PRIMARY KEY, ingredient_name varchar(100), amount int, - unit varchar(50), + unit varchar(50) ); -- Describes what ingredients goes into what recipe @@ -49,7 +47,7 @@ CREATE TABLE IF NOT EXISTS recipe_contents ( recipe_id int, ingredient_id int, amount int, - PRIMARY KEY (recipe_id, ingredient_id), + PRIMARY KEY (recipe_id, ingredient_id) ); -------------------------------------------- @@ -80,6 +78,6 @@ CREATE TABLE IF NOT EXISTS pallet_contents ( CREATE TABLE IF NOT EXISTS delivery_bill ( delivery_id int PRIMARY KEY, order_id int, - delivery_date date DEFAULT NOW(), + delivery_date date DEFAULT NOW, FOREIGN KEY (order_id) REFERENCES Orders(order_id) ); \ No newline at end of file diff --git a/app/Migrations/initial-data.sql b/app/Migrations/initial-data.sql index 2d34cb0..4dbbd05 100644 --- a/app/Migrations/initial-data.sql +++ b/app/Migrations/initial-data.sql @@ -1,5 +1,5 @@ -- Inserts here -INSERT INTO +INSERT OR IGNORE INTO customers (customer_id, customer_name, customer_address) VALUES (1, 'Bjudkakor AB', 'Ystad'), @@ -12,7 +12,7 @@ VALUES (8, 'Småbröd AB', 'Malmö'); INSERT INTO - recipes (name) + recipes (recipe_name) VALUES ('Nut ring'), ('Nut cookie'),