From aa5a6d212f6237ab696cb0f5b00d3d5e762d5fec Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 16 Dec 2020 20:01:32 +0530 Subject: rework tables --- migrations/2020-12-13-140215_all_tables/down.sql | 11 ++++++ migrations/2020-12-13-140215_all_tables/up.sql | 47 ++++++++++++++++++++++++ shell.nix | 2 + 3 files changed, 60 insertions(+) create mode 100644 migrations/2020-12-13-140215_all_tables/down.sql create mode 100644 migrations/2020-12-13-140215_all_tables/up.sql diff --git a/migrations/2020-12-13-140215_all_tables/down.sql b/migrations/2020-12-13-140215_all_tables/down.sql new file mode 100644 index 0000000..9c554a2 --- /dev/null +++ b/migrations/2020-12-13-140215_all_tables/down.sql @@ -0,0 +1,11 @@ +-- This file should undo anything in `up.sql` + +drop table customer; + +drop table product; + +drop table cart_items; + +drop table rating; + +drop table transaction; diff --git a/migrations/2020-12-13-140215_all_tables/up.sql b/migrations/2020-12-13-140215_all_tables/up.sql new file mode 100644 index 0000000..527b926 --- /dev/null +++ b/migrations/2020-12-13-140215_all_tables/up.sql @@ -0,0 +1,47 @@ +-- Your SQL goes here + +create table customer ( + id integer primary key auto_increment, + username varchar(255) not null unique, + password varchar(255) not null, + phone_number varchar(10) not null, + email_id varchar(255) not null, + address text(500) +); + +create table product ( + id integer primary key auto_increment, + name varchar(255) not null, + kind varchar(255), + price float not null, + description varchar(255) +); + +create table cart_items ( + cart_id integer, + product_id integer, + constraint cart_items_pk primary key (cart_id, product_id), + foreign key (cart_id) references customer(id), + foreign key (product_id) references product(id) +); + +create table rating ( + id integer primary key auto_increment, + comment_text text(500), + comment_date date default curdate(), + product_id integer, + customer_id integer, + + stars integer check (stars >= 0 AND stars <= 5), + foreign key (customer_id) references customer(id), + foreign key (product_id) references product(id) +); + +create table transaction ( + id integer primary key auto_increment, + payment_type varchar(255) not null, + amount float not null, + customer_id integer, + + foreign key (customer_id) references customer(id) +); diff --git a/shell.nix b/shell.nix index 9f6b23c..9805d80 100644 --- a/shell.nix +++ b/shell.nix @@ -27,5 +27,7 @@ in curl diesel-cli libmysqlclient + jq + python3 ]; } -- cgit v1.2.3