-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from GSG-G7/database
setup Database
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { join } = require('path'); | ||
const { readFileSync } = require('fs'); | ||
const connection = require('./connection'); | ||
|
||
let sql = readFileSync(join(__dirname, 'build_db.sql')).toString(); | ||
|
||
connection | ||
.query(sql) | ||
.then(console.log('Build Successfully', new Date())) | ||
.catch((err) => console.log(err)); | ||
|
||
module.exports = { connection }; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
BEGIN; | ||
DROP table if exists users, tweets, comments CASCADE; | ||
create table users ( | ||
id serial Primary key, | ||
name varchar(20), | ||
email varchar UNIQUE, | ||
password varchar(20), | ||
imgUrl varchar, | ||
gender varchar(10), | ||
birthday varchar, | ||
country varchar(30), | ||
bio text | ||
); | ||
|
||
create table tweets( | ||
id serial primary key, | ||
content text NOT NULL, | ||
publishTime timestamp, | ||
user_id integer references users(id) | ||
); | ||
|
||
create table comments( | ||
id serial primary key, | ||
content text, | ||
publishTime timestamp, | ||
user_id integer references users(id), | ||
tweet_id integer references tweets(id) | ||
); | ||
|
||
insert into users (name,email,password,imgUrl,gender,birthday, country, bio) values ('Fares','fares@gmail.com','fares1998','hgjjjkhghghjjhj','male','29/5/1998','Palestine','Web fullstack Developer'); | ||
insert into tweets (user_id,content,publishTime) values (1,'Be optimistic ^_^','2019-08-27T13:08:15.369Z'); | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const { Pool } = require('pg'); | ||
require('env2')('./config.env') | ||
|
||
let dbUrl = process.env.DB_URL; | ||
|
||
const options = { | ||
connectionString: dbUrl, | ||
ssl: true, | ||
}; | ||
|
||
if (!dbUrl) throw new Error('DB_URL not found'); | ||
module.exports = new Pool(options); |