-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(database): setup and configure postgres database
- install and configure pg to export two pools - add normal database and test database urls to .env - create database schema - setup npm scripts to manage database [Finishes #160819060]
- Loading branch information
Showing
5 changed files
with
149 additions
and
7 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,3 @@ | ||
PORT=[server_port_number] | ||
DATABASE_URL=postgres://[username]@[server]:[port]/[database_name] | ||
TEST_DATABASE_URL=postgres://[username]@[server]:[port]/[database_name] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,16 @@ | ||
import dotenv from 'dotenv'; | ||
import { Pool } from 'pg'; | ||
|
||
dotenv.config(); | ||
|
||
const env = process.env.NODE_ENV || 'development'; | ||
let pool; | ||
let testPool; | ||
|
||
if (env === 'test') { | ||
testPool = new Pool({ connectionString: process.env.TEST_DATABASE_URL }); | ||
} else { | ||
pool = new Pool({ connectionString: process.env.DATABASE_URL }); | ||
} | ||
|
||
export default { pool, testPool }; |
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,21 @@ | ||
CREATE TABLE IF NOT EXISTS users ( | ||
id serial PRIMARY KEY, | ||
name VARCHAR(50) NOT NULL, | ||
email VARCHAR(50) NOT NULL, | ||
password VARCHAR(255) NOT NULL, | ||
is_admin BOOLEAN NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS menu ( | ||
id serial PRIMARY KEY, | ||
food_name VARCHAR(255) NOT NULL, | ||
price REAL NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS orders ( | ||
id serial PRIMARY KEY, | ||
item INTEGER REFERENCES menu(id), | ||
author INTEGER REFERENCES users(id), | ||
date DATE NOT NULL DEFAULT CURRENT_DATE, | ||
status VARCHAR(50) NOT NULL DEFAULT 'new' | ||
); |