Skip to content

Commit

Permalink
Setting up schema, for the database
Browse files Browse the repository at this point in the history
Related #1
Co-authored-by: sakireid <[email protected]>
  • Loading branch information
designaky committed Jun 1, 2021
1 parent efd66a1 commit a04cc93
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
72 changes: 72 additions & 0 deletions database/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

BEGIN;

DROP TABLE IF EXISTS user_table, sessions_table, itineraries_table, imgs_table, mapspoints_table, reviews_table CASCADE;

CREATE TABLE user_table (
id SERIAL PRIMARY KEY,
username TEXT UNIQUE NOT NULL,
email TEXT UNIQUE NOT NULL,
password TEXT NOT NULL
);

CREATE TABLE sessions_table (
sid TEXT PRIMARY KEY,
data JSON NOT NULL
);

CREATE TABLE itineraries_table (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES user_table(id) ON DELETE CASCADE,
name TEXT NOT NULL,
country TEXT NOT NULL,
need_car BOOLEAN NOT NULL,
budget DECIMAL,
duration INTEGER NOT NULL,
description JSON NOT NULL,
created_at TIMESTAMP
);


CREATE TABLE imgs_table (
id SERIAL PRIMARY KEY,
itinerary_id INTEGER REFERENCES itineraries_table(id) ON DELETE CASCADE,
img BYTEA
);

CREATE TABLE mapspoints_table (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES user_table(id) ON DELETE CASCADE,
itinerary_id INTEGER REFERENCES itineraries_table(id) ON DELETE CASCADE,
name TEXT NOT NULL,
longitude DECIMAL,
latitude DECIMAL
);


CREATE TABLE reviews_table (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES user_table(id) ON DELETE CASCADE,
stars INTEGER NOT NULL,
review TEXT NOT NULL,
itinerary_id INTEGER REFERENCES itineraries_table(id) ON DELETE CASCADE,
created_at TIMESTAMP
);

INSERT INTO user_table (email, password, username) VALUES
(
'[email protected]',
'$2a$10$vzgLAxSa1k293giKSbVWi.GgSGmb1JB/kD1qWIg.mrUlt7UwVDCWG',
'Test Testington'
);

INSERT INTO sessions_table (sid, data) VALUES
(
'abc123',
'{"test":"stuff"}'
);

INSERT INTO itineraries_table ( user_id, name, country, need_car, budget, duration, description, created_at) VALUES
(1, 'Southwest England', 'England', TRUE, 1400, 10, '{"description": "Day One- Oxford, Stratford Upon Avon Day Two: Cotswolds Day Three: Bath, Wells, Glastonbury Day Four: Exmoor National Park, Croyde Bay, (Barnstaple), Bude Day Five: Cornwall- Tintagel, Saint Michael’s Mount, Land’s End, Minack Theatre, Mousehole Day Six: Lizard Point, Pendennis Castle, Dartmoor National Park, Exeter Day Seven: Beer, Seaton Down, Lyme Regis, Durdle Door, Lulworth Cove Day Eight: Portsmouth, Arundel, Brighton Day Nine: Brighton, Beachy Head, Rye Day ten: Rye, White Cliffs of Dover, Canterbury"}', (SELECT CURRENT_TIMESTAMP));

COMMIT;
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-react": "^7.24.0"
}
}
}
2 changes: 1 addition & 1 deletion scripts/db:build
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# stop script when an error occurs
set -e

psql example -q -f "./database/init.sql"
psql final_project -q -f "./database/init.sql"
echo "Populated database tables"

0 comments on commit a04cc93

Please sign in to comment.