@@ -10,22 +10,22 @@ const sneakersFile = fs.readFileSync(
1010 path . join ( dirname ( currentPath ) , "../config/data/data.json" )
1111) ;
1212const sneakersData = JSON . parse ( sneakersFile ) ;
13-
1413const createSneakersTable = async ( ) => {
1514 const createSneakersTableQuery = `
16- CREATE TABLE IF NOT EXISTS sneakers (
17- id serial PRIMARY KEY,
18- name varchar(100) NOT NULL,
19- brand varchar(100) NOT NULL,
20- description text NOT NULL,
21- price money NOT NULL,
22- size numeric(7, 2) NOT NULL,
23- color varchar(50) NOT NULL,
24- stockquantity integer NOT NULL,
25- category varchar(50) NOT NULL,
26- targetaudience varchar(50) NOT NULL
27- );
15+ CREATE TABLE IF NOT EXISTS sneakers (
16+ id serial PRIMARY KEY,
17+ name varchar(100) NOT NULL,
18+ brand varchar(100) NOT NULL,
19+ description text NOT NULL,
20+ price money NOT NULL,
21+ size numeric(7, 2) NOT NULL,
22+ color varchar(50) NOT NULL,
23+ stock_quantity integer NOT NULL,
24+ category varchar(50) NOT NULL,
25+ target_audience varchar(50) NOT NULL
26+ );
2827 ` ;
28+ // console.log(sneakersData);
2929
3030 try {
3131 const res = await pool . query ( createSneakersTableQuery ) ;
@@ -38,10 +38,10 @@ const createSneakersTable = async () => {
3838const createImagesTable = async ( ) => {
3939 const createImagesTableQuery = `
4040 CREATE TABLE IF NOT EXISTS images (
41- imageid serial PRIMARY KEY,
42- productid integer NOT NULL,
43- imageurl text NOT NULL,
44- FOREIGN KEY(productid ) REFERENCES sneakers(id)
41+ id serial PRIMARY KEY,
42+ product_id integer NOT NULL,
43+ image_url text NOT NULL,
44+ FOREIGN KEY(product_id ) REFERENCES sneakers(id)
4545 );
4646 ` ;
4747
@@ -56,9 +56,9 @@ const createImagesTable = async () => {
5656const seedSneakersTable = async ( ) => {
5757 await createSneakersTable ( ) ;
5858
59- sneakersData . forEach ( ( sneaker ) => {
59+ await sneakersData . forEach ( ( sneaker ) => {
6060 const insertQuery = {
61- text : "INSERT INTO sneakers (name, brand, description, price, size, color, stockquantity , category, targetaudience ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)" ,
61+ text : "INSERT INTO sneakers (name, brand, description, price, size, color, stock_quantity , category, target_audience ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)" ,
6262 } ;
6363
6464 const values = [
@@ -68,9 +68,9 @@ const seedSneakersTable = async () => {
6868 sneaker . price ,
6969 sneaker . size ,
7070 sneaker . color ,
71- sneaker . stockquantity ,
71+ sneaker . stock_quantity ,
7272 sneaker . category ,
73- sneaker . targetaudience ,
73+ sneaker . target_audience ,
7474 ] ;
7575
7676 try {
@@ -88,10 +88,10 @@ const seedImagesTable = async () => {
8888
8989 sneakersData . forEach ( ( sneaker ) => {
9090 const insertImageQuery = {
91- text : "INSERT INTO images (productid, imageurl ) VALUES ($1, $2)" ,
91+ text : "INSERT INTO images (product_id, image_url ) VALUES ($1, $2)" ,
9292 } ;
9393
94- const imageValues = [ sneaker . id , sneaker . img_url ] ;
94+ const imageValues = [ sneaker . id , sneaker . image_url [ 0 ] ] ;
9595
9696 try {
9797 pool . query ( insertImageQuery , imageValues ) ;
@@ -101,15 +101,16 @@ const seedImagesTable = async () => {
101101 }
102102 } ) ;
103103} ;
104+
104105const createReviewsTable = async ( ) => {
105106 const createReviewsTableQuery = `
106107 CREATE TABLE IF NOT EXISTS reviews (
107- reviewid serial PRIMARY KEY,
108- productid integer NOT NULL,
109- userid integer NOT NULL,
108+ review_id serial PRIMARY KEY,
109+ product_id integer NOT NULL,
110+ user_id integer NOT NULL,
110111 rating integer NOT NULL,
111- reviewtext text NOT NULL,
112- reviewdate date NOT NULL
112+ review_text text NOT NULL,
113+ review_date date NOT NULL
113114 );
114115 ` ;
115116
@@ -122,12 +123,13 @@ const createReviewsTable = async () => {
122123} ;
123124const createUsersTable = async ( ) => {
124125 const createUsersTableQuery = `
125- CREATE TABLE IF NOT EXISTS user (
126+ CREATE TABLE IF NOT EXISTS users (
126127 id serial PRIMARY KEY,
127- googleid integer NOT NULL,
128+ google_id integer UNIQUE NOT NULL,
128129 username varchar(100) NOT NULL,
129130 avatarurl varchar(500) NOT NULL,
130- accesstoken varchar(500) NOT NULL
131+ access_token varchar(500) NOT NULL,
132+ is_admin boolean NOT NULL
131133 );
132134 ` ;
133135
@@ -141,15 +143,15 @@ const createUsersTable = async () => {
141143
142144const createUserAddressTable = async ( ) => {
143145 const createUserAddressTableQuery = `
144- CREATE TABLE IF NOT EXISTS useraddress (
146+ CREATE TABLE IF NOT EXISTS user_address (
145147 id serial PRIMARY KEY,
146- userid integer NOT NULL,
148+ user_id integer NOT NULL,
147149 address varchar(255) NOT NULL,
148150 city varchar(100) NOT NULL,
149- postalcode varchar(10) NOT NULL,
151+ postal_code varchar(10) NOT NULL,
150152 country varchar(100) NOT NULL,
151153 phone varchar(20) NOT NULL,
152- FOREIGN KEY(userid) REFERENCES user (id)
154+ FOREIGN KEY(userid) REFERENCES users (id)
153155 );
154156 ` ;
155157
0 commit comments