From 044385c18318b50f8e3a1d4107541cd90df6d2f0 Mon Sep 17 00:00:00 2001 From: vextv Date: Mon, 18 Nov 2024 21:12:50 +0100 Subject: [PATCH 1/2] updated sql scripts --- database/db_scripts/create_db.sql | 48 ++++----- database/db_scripts/test.sql | 170 ++++++++++++++++++++++++++++++ database/query/get_users.js | 4 +- scripts/login.js | 4 +- 4 files changed, 198 insertions(+), 28 deletions(-) create mode 100644 database/db_scripts/test.sql diff --git a/database/db_scripts/create_db.sql b/database/db_scripts/create_db.sql index 88cc2f3..2093833 100644 --- a/database/db_scripts/create_db.sql +++ b/database/db_scripts/create_db.sql @@ -12,8 +12,8 @@ CREATE TABLE 'user' passwd varchar(255), passwd_hash_algo varchar(255), is_admin bool, - created_at timestamp, - modified_at timestamp, + created_at int8, + modified_at int8, PRIMARY KEY (id), UNIQUE (email, passwd) ); @@ -48,8 +48,8 @@ CREATE TABLE 'shopping_session' id int, user_id varchar(255), total decimal, - created_at timestamp, - modified_at timestamp, + created_at int8, + modified_at int8, UNIQUE (user_id) ); @@ -59,8 +59,8 @@ CREATE TABLE 'cart_item' session_id int, product_id int, quantity int, - created_at timestamp, - modified_at timestamp + created_at int8, + modified_at int8 ); CREATE TABLE 'payment_details' @@ -70,8 +70,8 @@ CREATE TABLE 'payment_details' amount int, provider varchar(255), status varchar(255), - created_at timestamp, - modified_at timestamp + created_at int8, + modified_at int8 ); CREATE TABLE 'order_items' @@ -80,8 +80,8 @@ CREATE TABLE 'order_items' order_id int, product_id int, quantity int, - created_at timestamp, - modified_at timestamp + created_at int8, + modified_at int8 ); CREATE TABLE 'order_details' @@ -90,8 +90,8 @@ CREATE TABLE 'order_details' user_id varchar(255), total decimal, payment_id int, - created_at timestamp, - modified_at timestamp + created_at int8, + modified_at int8 ); CREATE TABLE 'product' @@ -107,9 +107,9 @@ CREATE TABLE 'product' inventory_id int, price decimal, discount_id int, - created_at timestamp, - modified_at timestamp, - deleted_at timestamp + created_at int8, + modified_at int8, + deleted_at int8 ); CREATE TABLE 'product_category' @@ -117,18 +117,18 @@ CREATE TABLE 'product_category' id int, name varchar(255), description text, - created_at timestamp, - modified_at timestamp, - deleted_at timestamp + created_at int8, + modified_at int8, + deleted_at int8 ); CREATE TABLE 'product_inventory' ( id int, quantity int, - created_at timestamp, - modified_at timestamp, - deleted_at timestamp + created_at int8, + modified_at int8, + deleted_at int8 ); CREATE TABLE 'discount' @@ -138,7 +138,7 @@ CREATE TABLE 'discount' description text, discount_percent decimal, active bool, - created_at timestamp, - modified_at timestamp, - deleted_at timestamp + created_at int8, + modified_at int8, + deleted_at int8 ) \ No newline at end of file diff --git a/database/db_scripts/test.sql b/database/db_scripts/test.sql new file mode 100644 index 0000000..70f3efb --- /dev/null +++ b/database/db_scripts/test.sql @@ -0,0 +1,170 @@ +CREATE TABLE `discount` +( + `deleted_at` INT(8) NOT NULL, + `name` VARCHAR(255) NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `description` TEXT NOT NULL, + `discount_percent` DECIMAL(8, 2) NOT NULL, + `modified_at` INT(8) NOT NULL, + `created_at` INT(8) NOT NULL, + `active` BOOLEAN NOT NULL +); +CREATE TABLE `user_address` +( + `address_line1` VARCHAR(255) NOT NULL, + `city` VARCHAR(255) NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `country` VARCHAR(2) NOT NULL, + `user_id` INT NOT NULL, + `mobile` VARCHAR(255) NOT NULL, + `postal_code` INT NOT NULL, + `address_line2` VARCHAR(255) NOT NULL, + `telephone` VARCHAR(255) NOT NULL +); +ALTER TABLE + `user_address` + ADD UNIQUE `user_address_mobile_unique` (`mobile`); +ALTER TABLE + `user_address` + ADD UNIQUE `user_address_telephone_unique` (`telephone`); +CREATE TABLE `product_inventory` +( + `created_at` INT(8) NOT NULL, + `modified_at` INT(8) NOT NULL, + `quantity` INT NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `deleted_at` INT(8) NOT NULL +); +CREATE TABLE `payment_details` +( + `order_id` INT NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `status` VARCHAR(255) NOT NULL, + `provider` VARCHAR(255) NOT NULL, + `modified_at` INT(8) NOT NULL, + `amount` INT NOT NULL, + `created_at` INT(8) NOT NULL +); +CREATE TABLE `order_details` +( + `payment_id` INT NOT NULL, + `total` DECIMAL(8, 2) NOT NULL, + `modified_at` INT(8) NOT NULL, + `created_at` INT(8) NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `user_id` INT NOT NULL +); +CREATE TABLE `oder_items` +( + `modified_at` INT(8) NOT NULL, + `user_id` BIGINT NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `quantity` INT NOT NULL, + `order_id` INT NOT NULL, + `created_at` INT(8) NOT NULL, + `product_id` INT NOT NULL +); +CREATE TABLE `user_payment` +( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `provider` VARCHAR(255) NOT NULL, + `account_no` VARCHAR(255) NOT NULL, + `expiry` DATE NOT NULL, + `payment_type` VARCHAR(255) NOT NULL, + `user_id` INT NOT NULL +); +CREATE TABLE `product` +( + `category_id` INT NOT NULL, + `model` VARCHAR(255) NOT NULL, + `color` VARCHAR(255) NOT NULL, + `engine` VARCHAR(255) NOT NULL, + `description` TEXT NOT NULL, + `make` VARCHAR(255) NOT NULL, + `inventory_id` INT NOT NULL, + `discount_id` INT NOT NULL, + `created_at` INT(8) NOT NULL, + `name` VARCHAR(255) NOT NULL, + `deleted_at` INT(8) NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `modified_at` INT(8) NOT NULL, + `price` DECIMAL(8, 2) NOT NULL +); +CREATE TABLE `product_category` +( + `created_at` INT(8) NOT NULL, + `name` VARCHAR(255) NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `modified_at` INT(8) NOT NULL, + `desc` TEXT NOT NULL, + `deleted_at` INT(8) NOT NULL +); +CREATE TABLE `user` +( + `is_active` BOOLEAN NOT NULL, + `lower_name` VARCHAR(255) NOT NULL, + `email` VARCHAR(255) NOT NULL, + `passwd_hash_algo` VARCHAR(255) NOT NULL, + `modified_at` INT(8) NOT NULL, + `is_admin` BOOLEAN NOT NULL, + `name` VARCHAR(255) NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `created_at` INT(8) NOT NULL, + `passwd` VARCHAR(255) NOT NULL +); +ALTER TABLE + `user` + ADD UNIQUE `user_email_unique` (`email`); +CREATE TABLE `shopping_session` +( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `created_at` INT(8) NOT NULL, + `user_id` INT NOT NULL, + `modified_at` INT(8) NOT NULL, + `total` DECIMAL(8, 2) NOT NULL +); +CREATE TABLE `cart_item` +( + `product_id` INT NOT NULL, + `session_id` INT NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `created_at` INT(8) NOT NULL, + `modified_at` INT(8) NOT NULL, + `quantity` INT NOT NULL +); +ALTER TABLE + `product` + ADD CONSTRAINT `product_inventory_id_foreign` FOREIGN KEY (`inventory_id`) REFERENCES `product_inventory` (`id`); +ALTER TABLE + `oder_items` + ADD CONSTRAINT `oder_items_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `order_details` (`id`); +ALTER TABLE + `product` + ADD CONSTRAINT `product_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `product_category` (`id`); +ALTER TABLE + `order_details` + ADD CONSTRAINT `order_details_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); +ALTER TABLE + `cart_item` + ADD CONSTRAINT `cart_item_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`); +ALTER TABLE + `oder_items` + ADD CONSTRAINT `oder_items_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`); +ALTER TABLE + `user_address` + ADD CONSTRAINT `user_address_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); +ALTER TABLE + `order_details` + ADD CONSTRAINT `order_details_payment_id_foreign` FOREIGN KEY (`payment_id`) REFERENCES `payment_details` (`id`); +ALTER TABLE + `product` + ADD CONSTRAINT `product_discount_id_foreign` FOREIGN KEY (`discount_id`) REFERENCES `discount` (`id`); +ALTER TABLE + `user_payment` + ADD CONSTRAINT `user_payment_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); +ALTER TABLE + `shopping_session` + ADD CONSTRAINT `shopping_session_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); +ALTER TABLE + `cart_item` + ADD CONSTRAINT `cart_item_session_id_foreign` FOREIGN KEY (`session_id`) REFERENCES `shopping_session` (`id`); \ No newline at end of file diff --git a/database/query/get_users.js b/database/query/get_users.js index 8669762..f899821 100644 --- a/database/query/get_users.js +++ b/database/query/get_users.js @@ -3,14 +3,14 @@ const mysql = require('mysql'); const connection = mysql.createConnection({ host: "localhost", user: "root", - password: "root", + password: "", database: "webshop" }); connection.connect(function (err) { if (err) throw err; console.log("Connected to database"); - connection.query("SELECT * FROM users", function (err, result) { + connection.query("SELECT * FROM user", function (err, result) { if (err) throw err; console.log(result); }) diff --git a/scripts/login.js b/scripts/login.js index dbef5a6..6d17a2a 100644 --- a/scripts/login.js +++ b/scripts/login.js @@ -2,6 +2,6 @@ let nameEl = document.getElementById("loginMail"); let passwordEl = document.getElementById("loginPassword"); function login() { - //console.log(nameEl.value) - //console.log(passwordEl.value) + console.log(nameEl.value) + console.log(passwordEl.value) } \ No newline at end of file -- 2.39.5 From 07e48d70a2dc53fcc3ee855cff8bb392283226cb Mon Sep 17 00:00:00 2001 From: vex Date: Tue, 19 Nov 2024 08:21:02 +0100 Subject: [PATCH 2/2] sql scripts are now functional for XAMPP (MariaDB) --- database/db_scripts/create_db.sql | 268 ++++++++++++++++-------------- database/db_scripts/delete_db.sql | 36 ++-- database/db_scripts/test.sql | 170 ------------------- 3 files changed, 171 insertions(+), 303 deletions(-) delete mode 100644 database/db_scripts/test.sql diff --git a/database/db_scripts/create_db.sql b/database/db_scripts/create_db.sql index 2093833..343c50e 100644 --- a/database/db_scripts/create_db.sql +++ b/database/db_scripts/create_db.sql @@ -1,144 +1,170 @@ -CREATE DATABASE 'webshop' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci; - --- example link: https://fabric.inc/blog/commerce/ecommerce-database-design-example - -CREATE TABLE 'user' +CREATE TABLE `discount` ( - id int NOT NULL AUTO_INCREMENT, - lower_name varchar(255), - name varchar(255) NOT NULL, - full_name varchar(255), - email varchar(255) NOT NULL, - passwd varchar(255), - passwd_hash_algo varchar(255), - is_admin bool, - created_at int8, - modified_at int8, - PRIMARY KEY (id), - UNIQUE (email, passwd) + `deleted_at` INT(8) NOT NULL, + `name` VARCHAR(255) NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `description` TEXT NOT NULL, + `discount_percent` DECIMAL(8, 2) NOT NULL, + `modified_at` INT(8) NOT NULL, + `created_at` INT(8) NOT NULL, + `active` BOOLEAN NOT NULL ); - -CREATE TABLE 'user_address' +CREATE TABLE `user_address` ( - id int, - user_id int, - address_line1 varchar(255), - address_line2 varchar(255), - city varchar(255), - postal_code varchar(255), - country varchar(2), - telephone varchar(255), - mobile varchar(255), - UNIQUE (telephone, mobile, user_id) + `address_line1` VARCHAR(255) NOT NULL, + `city` VARCHAR(255) NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `country` VARCHAR(2) NOT NULL, + `user_id` INT UNSIGNED NOT NULL, + `mobile` VARCHAR(255) NOT NULL, + `postal_code` INT NOT NULL, + `address_line2` VARCHAR(255) NOT NULL, + `telephone` VARCHAR(255) NOT NULL ); - -CREATE TABLE 'user_payment' +ALTER TABLE + `user_address` + ADD UNIQUE `user_address_mobile_unique` (`mobile`); +ALTER TABLE + `user_address` + ADD UNIQUE `user_address_telephone_unique` (`telephone`); +CREATE TABLE `product_inventory` ( - id int, - user_id int, - payment_type varchar(255), - provider varchar(255), - account_no int, - expiry date, - UNIQUE (user_id) + `created_at` INT(8) NOT NULL, + `modified_at` INT(8) NOT NULL, + `quantity` INT NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `deleted_at` INT(8) NOT NULL ); - -CREATE TABLE 'shopping_session' +CREATE TABLE `payment_details` ( - id int, - user_id varchar(255), - total decimal, - created_at int8, - modified_at int8, - UNIQUE (user_id) + `order_id` INT NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `status` VARCHAR(255) NOT NULL, + `provider` VARCHAR(255) NOT NULL, + `modified_at` INT(8) NOT NULL, + `amount` INT NOT NULL, + `created_at` INT(8) NOT NULL ); - -CREATE TABLE 'cart_item' +CREATE TABLE `order_details` ( - id int, - session_id int, - product_id int, - quantity int, - created_at int8, - modified_at int8 + `payment_id` INT UNSIGNED NOT NULL, + `total` DECIMAL(8, 2) NOT NULL, + `modified_at` INT(8) NOT NULL, + `created_at` INT(8) NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `user_id` INT UNSIGNED NOT NULL ); - -CREATE TABLE 'payment_details' +CREATE TABLE `order_items` ( - id int, - order_id int, - amount int, - provider varchar(255), - status varchar(255), - created_at int8, - modified_at int8 + `modified_at` INT(8) NOT NULL, + `user_id` BIGINT NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `quantity` INT NOT NULL, + `order_id` INT UNSIGNED NOT NULL, + `created_at` INT(8) NOT NULL, + `product_id` INT UNSIGNED NOT NULL ); - -CREATE TABLE 'order_items' +CREATE TABLE `user_payment` ( - id int, - order_id int, - product_id int, - quantity int, - created_at int8, - modified_at int8 + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `provider` VARCHAR(255) NOT NULL, + `account_no` VARCHAR(255) NOT NULL, + `expiry` DATE NOT NULL, + `payment_type` VARCHAR(255) NOT NULL, + `user_id` INT UNSIGNED NOT NULL ); - -CREATE TABLE 'order_details' +CREATE TABLE `product` ( - id int, - user_id varchar(255), - total decimal, - payment_id int, - created_at int8, - modified_at int8 + `category_id` INT UNSIGNED NOT NULL, + `model` VARCHAR(255) NOT NULL, + `color` VARCHAR(255) NOT NULL, + `engine` VARCHAR(255) NOT NULL, + `description` TEXT NOT NULL, + `make` VARCHAR(255) NOT NULL, + `inventory_id` INT UNSIGNED NOT NULL, + `discount_id` INT UNSIGNED NOT NULL, + `created_at` INT(8) NOT NULL, + `name` VARCHAR(255) NOT NULL, + `deleted_at` INT(8) NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `modified_at` INT(8) NOT NULL, + `price` DECIMAL(8, 2) NOT NULL ); - -CREATE TABLE 'product' +CREATE TABLE `product_category` ( - id int NOT NULL, - name varchar(255), - color varchar(255), - make varchar(255), - model varchar(255) NOT NULL, - engine varchar(255), - description text, - category_id int, - inventory_id int, - price decimal, - discount_id int, - created_at int8, - modified_at int8, - deleted_at int8 + `created_at` INT(8) NOT NULL, + `name` VARCHAR(255) NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `modified_at` INT(8) NOT NULL, + `desc` TEXT NOT NULL, + `deleted_at` INT(8) NOT NULL ); - -CREATE TABLE 'product_category' +CREATE TABLE `user` ( - id int, - name varchar(255), - description text, - created_at int8, - modified_at int8, - deleted_at int8 + `is_active` BOOLEAN NOT NULL, + `lower_name` VARCHAR(255) NOT NULL, + `email` VARCHAR(255) NOT NULL, + `passwd_hash_algo` VARCHAR(255) NOT NULL, + `modified_at` INT(8) NOT NULL, + `is_admin` BOOLEAN NOT NULL, + `name` VARCHAR(255) NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `created_at` INT(8) NOT NULL, + `passwd` VARCHAR(255) NOT NULL ); - -CREATE TABLE 'product_inventory' +ALTER TABLE + `user` + ADD UNIQUE `user_email_unique` (`email`); +CREATE TABLE `shopping_session` ( - id int, - quantity int, - created_at int8, - modified_at int8, - deleted_at int8 + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `created_at` INT(8) NOT NULL, + `user_id` INT UNSIGNED NOT NULL, + `modified_at` INT(8) NOT NULL, + `total` DECIMAL(8, 2) NOT NULL ); - -CREATE TABLE 'discount' +CREATE TABLE `cart_item` ( - id int, - name varchar(255), - description text, - discount_percent decimal, - active bool, - created_at int8, - modified_at int8, - deleted_at int8 -) \ No newline at end of file + `product_id` INT UNSIGNED NOT NULL, + `session_id` INT UNSIGNED NOT NULL, + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `created_at` INT(8) NOT NULL, + `modified_at` INT(8) NOT NULL, + `quantity` INT NOT NULL +); +ALTER TABLE + `product` + ADD CONSTRAINT `product_inventory_id_foreign` FOREIGN KEY (`inventory_id`) REFERENCES `product_inventory` (`id`); +ALTER TABLE + `order_items` + ADD CONSTRAINT `order_items_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `order_details` (`id`); +ALTER TABLE + `product` + ADD CONSTRAINT `product_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `product_category` (`id`); +ALTER TABLE + `order_details` + ADD CONSTRAINT `order_details_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); +ALTER TABLE + `cart_item` + ADD CONSTRAINT `cart_item_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`); +ALTER TABLE + `order_items` + ADD CONSTRAINT `order_items_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`); +ALTER TABLE + `user_address` + ADD CONSTRAINT `user_address_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); +ALTER TABLE + `order_details` + ADD CONSTRAINT `order_details_payment_id_foreign` FOREIGN KEY (`payment_id`) REFERENCES `payment_details` (`id`); +ALTER TABLE + `product` + ADD CONSTRAINT `product_discount_id_foreign` FOREIGN KEY (`discount_id`) REFERENCES `discount` (`id`); +ALTER TABLE + `user_payment` + ADD CONSTRAINT `user_payment_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); +ALTER TABLE + `shopping_session` + ADD CONSTRAINT `shopping_session_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); +ALTER TABLE + `cart_item` + ADD CONSTRAINT `cart_item_session_id_foreign` FOREIGN KEY (`session_id`) REFERENCES `shopping_session` (`id`); \ No newline at end of file diff --git a/database/db_scripts/delete_db.sql b/database/db_scripts/delete_db.sql index 6549ee6..29a0cf7 100644 --- a/database/db_scripts/delete_db.sql +++ b/database/db_scripts/delete_db.sql @@ -1,12 +1,24 @@ -DROP TABLE IF EXISTS 'user'; -DROP TABLE IF EXISTS 'user_address'; -DROP TABLE IF EXISTS 'user_payment'; -DROP TABLE IF EXISTS 'shopping_session'; -DROP TABLE IF EXISTS 'cart_item'; -DROP TABLE IF EXISTS 'payment_details'; -DROP TABLE IF EXISTS 'order_items'; -DROP TABLE IF EXISTS 'order_details'; -DROP TABLE IF EXISTS 'product'; -DROP TABLE IF EXISTS 'product_category'; -DROP TABLE IF EXISTS 'product_inventory'; -DROP TABLE IF EXISTS 'discount'; +drop table if exists cart_item; + +drop table if exists discount; + +drop table if exists oder_items; + +drop table if exists order_details; + +drop table if exists payment_details; + +drop table if exists product; + +drop table if exists product_category; + +drop table if exists product_inventory; + +drop table if exists shopping_session; + +drop table if exists user; + +drop table if exists user_address; + +drop table if exists user_payment; + diff --git a/database/db_scripts/test.sql b/database/db_scripts/test.sql deleted file mode 100644 index 70f3efb..0000000 --- a/database/db_scripts/test.sql +++ /dev/null @@ -1,170 +0,0 @@ -CREATE TABLE `discount` -( - `deleted_at` INT(8) NOT NULL, - `name` VARCHAR(255) NOT NULL, - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `description` TEXT NOT NULL, - `discount_percent` DECIMAL(8, 2) NOT NULL, - `modified_at` INT(8) NOT NULL, - `created_at` INT(8) NOT NULL, - `active` BOOLEAN NOT NULL -); -CREATE TABLE `user_address` -( - `address_line1` VARCHAR(255) NOT NULL, - `city` VARCHAR(255) NOT NULL, - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `country` VARCHAR(2) NOT NULL, - `user_id` INT NOT NULL, - `mobile` VARCHAR(255) NOT NULL, - `postal_code` INT NOT NULL, - `address_line2` VARCHAR(255) NOT NULL, - `telephone` VARCHAR(255) NOT NULL -); -ALTER TABLE - `user_address` - ADD UNIQUE `user_address_mobile_unique` (`mobile`); -ALTER TABLE - `user_address` - ADD UNIQUE `user_address_telephone_unique` (`telephone`); -CREATE TABLE `product_inventory` -( - `created_at` INT(8) NOT NULL, - `modified_at` INT(8) NOT NULL, - `quantity` INT NOT NULL, - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `deleted_at` INT(8) NOT NULL -); -CREATE TABLE `payment_details` -( - `order_id` INT NOT NULL, - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `status` VARCHAR(255) NOT NULL, - `provider` VARCHAR(255) NOT NULL, - `modified_at` INT(8) NOT NULL, - `amount` INT NOT NULL, - `created_at` INT(8) NOT NULL -); -CREATE TABLE `order_details` -( - `payment_id` INT NOT NULL, - `total` DECIMAL(8, 2) NOT NULL, - `modified_at` INT(8) NOT NULL, - `created_at` INT(8) NOT NULL, - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `user_id` INT NOT NULL -); -CREATE TABLE `oder_items` -( - `modified_at` INT(8) NOT NULL, - `user_id` BIGINT NOT NULL, - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `quantity` INT NOT NULL, - `order_id` INT NOT NULL, - `created_at` INT(8) NOT NULL, - `product_id` INT NOT NULL -); -CREATE TABLE `user_payment` -( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `provider` VARCHAR(255) NOT NULL, - `account_no` VARCHAR(255) NOT NULL, - `expiry` DATE NOT NULL, - `payment_type` VARCHAR(255) NOT NULL, - `user_id` INT NOT NULL -); -CREATE TABLE `product` -( - `category_id` INT NOT NULL, - `model` VARCHAR(255) NOT NULL, - `color` VARCHAR(255) NOT NULL, - `engine` VARCHAR(255) NOT NULL, - `description` TEXT NOT NULL, - `make` VARCHAR(255) NOT NULL, - `inventory_id` INT NOT NULL, - `discount_id` INT NOT NULL, - `created_at` INT(8) NOT NULL, - `name` VARCHAR(255) NOT NULL, - `deleted_at` INT(8) NOT NULL, - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `modified_at` INT(8) NOT NULL, - `price` DECIMAL(8, 2) NOT NULL -); -CREATE TABLE `product_category` -( - `created_at` INT(8) NOT NULL, - `name` VARCHAR(255) NOT NULL, - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `modified_at` INT(8) NOT NULL, - `desc` TEXT NOT NULL, - `deleted_at` INT(8) NOT NULL -); -CREATE TABLE `user` -( - `is_active` BOOLEAN NOT NULL, - `lower_name` VARCHAR(255) NOT NULL, - `email` VARCHAR(255) NOT NULL, - `passwd_hash_algo` VARCHAR(255) NOT NULL, - `modified_at` INT(8) NOT NULL, - `is_admin` BOOLEAN NOT NULL, - `name` VARCHAR(255) NOT NULL, - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `created_at` INT(8) NOT NULL, - `passwd` VARCHAR(255) NOT NULL -); -ALTER TABLE - `user` - ADD UNIQUE `user_email_unique` (`email`); -CREATE TABLE `shopping_session` -( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `created_at` INT(8) NOT NULL, - `user_id` INT NOT NULL, - `modified_at` INT(8) NOT NULL, - `total` DECIMAL(8, 2) NOT NULL -); -CREATE TABLE `cart_item` -( - `product_id` INT NOT NULL, - `session_id` INT NOT NULL, - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `created_at` INT(8) NOT NULL, - `modified_at` INT(8) NOT NULL, - `quantity` INT NOT NULL -); -ALTER TABLE - `product` - ADD CONSTRAINT `product_inventory_id_foreign` FOREIGN KEY (`inventory_id`) REFERENCES `product_inventory` (`id`); -ALTER TABLE - `oder_items` - ADD CONSTRAINT `oder_items_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `order_details` (`id`); -ALTER TABLE - `product` - ADD CONSTRAINT `product_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `product_category` (`id`); -ALTER TABLE - `order_details` - ADD CONSTRAINT `order_details_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); -ALTER TABLE - `cart_item` - ADD CONSTRAINT `cart_item_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`); -ALTER TABLE - `oder_items` - ADD CONSTRAINT `oder_items_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`); -ALTER TABLE - `user_address` - ADD CONSTRAINT `user_address_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); -ALTER TABLE - `order_details` - ADD CONSTRAINT `order_details_payment_id_foreign` FOREIGN KEY (`payment_id`) REFERENCES `payment_details` (`id`); -ALTER TABLE - `product` - ADD CONSTRAINT `product_discount_id_foreign` FOREIGN KEY (`discount_id`) REFERENCES `discount` (`id`); -ALTER TABLE - `user_payment` - ADD CONSTRAINT `user_payment_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); -ALTER TABLE - `shopping_session` - ADD CONSTRAINT `shopping_session_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`); -ALTER TABLE - `cart_item` - ADD CONSTRAINT `cart_item_session_id_foreign` FOREIGN KEY (`session_id`) REFERENCES `shopping_session` (`id`); \ No newline at end of file -- 2.39.5