This repository was archived by the owner on Oct 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Setup backend DB and add example service #8
Open
Qrtn
wants to merge
28
commits into
master
Choose a base branch
from
setup_backend_db
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
fbb38f3
add checkin routes file
ashwin1104 d71af3a
Merge branch 'master' of https://github.com/hack4impact-uiuc/closegap…
ashwin1104 3c79fe4
create API readme
ashwin1104 bbce007
Install dotenv
Qrtn 0eb8cfe
Add default config for db
Qrtn 505f018
Install pg
Qrtn 28686d5
Install pg-promise
Qrtn 6ef6486
Add ruby db schema
Qrtn a0cbc74
Add db module
Qrtn fdc0033
Add schema-only and seeded db dumps
Qrtn 628e68a
Change var to const in app.js
Qrtn 5b69ecc
Add example route for accessing db via service
Qrtn 2dd6309
Add example service for student
Qrtn a2d11fc
Update example route with 404
Qrtn 578104c
Add setup script for dev db
Qrtn 3a6cb73
Add db setup instructions in backend readme
Qrtn 4865289
Update default dev.env config
Qrtn c69a39b
Differentiate dev environment in yarn start
Qrtn 56df922
Update dev.env.default config
Qrtn a94ae50
Fix linting
Qrtn 2f1e0b5
Fix setup db script not seeding data
Qrtn 6800a25
Export router from checkin route
Qrtn d59f041
Run prettier
Qrtn d93a304
Use http-status-codes
Qrtn 8b5de95
Add comments to db setup script
Qrtn 869c1d7
Remove checkin route comments
Qrtn 6fc2ec2
Remove return from route
Qrtn d7d9706
Fix statusCodes import
Qrtn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,56 @@ | ||
| # Closegap API | ||
|
|
||
| This folder contains the backend api of the application. | ||
|
|
||
| ## Setup DB | ||
|
|
||
| ### Install PostgreSQL | ||
|
|
||
| #### macOS | ||
|
|
||
| 1. Install [Homebrew](https://brew.sh). | ||
|
|
||
| 2. Install postgresql via Homebrew. | ||
|
|
||
| `$ brew install postgresql` | ||
|
|
||
| 3. Start postgresql and register it to launch on system start. | ||
|
|
||
| `$ brew services start postgresql` | ||
|
|
||
| #### Windows Subsystem for Linux (WSL) | ||
|
|
||
| 1. [Install postgresql.](https://github.com/michaeltreat/Windows-Subsystem-For-Linux-Setup-Guide/blob/master/readmes/installs/PostgreSQL.md) | ||
|
|
||
| 2. Start postgresql. | ||
|
|
||
| `$ sudo service postgresql start ` | ||
|
|
||
| ### Create database | ||
|
|
||
| Run setup script. Enter `n` if you do not wish to seed with initial data. | ||
|
|
||
| ``` | ||
| $ infra/setup_dev_db.sh | ||
| Seed database with initial data? [Y/n] y | ||
| ... | ||
| ``` | ||
|
|
||
| ## Configure App | ||
|
|
||
| ``` | ||
| $ cp config/dev.env.default config/dev.env | ||
| ``` | ||
|
|
||
| ## Install & Run | ||
|
|
||
| ```bash | ||
| yarn && yarn start | ||
| ``` | ||
|
|
||
| ## Test DB access | ||
|
|
||
| ``` | ||
| $ curl http://localhost:5000/students/1 | ||
| {"data":{"id":"1","user_id":"1","first_name":"Ipsum1","middle_name":"Lorem1","last_name":"Dolor1","birthdate":"2010-11-14T06:00:00.000Z","homeroom_teacher":"Amet1","grade":"1st","gender":"male","created_at":"2020-10-01T09:31:50.910Z","updated_at":"2020-10-01T09:31:50.976Z","school_name":"some school name"}}% | ||
| ``` |
This file contains hidden or 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,10 @@ | ||
| # PostgreSQL DB Configuration | ||
|
|
||
| PGDATABASE=closegap-api_development | ||
|
|
||
| PGHOST=localhost | ||
|
|
||
| PGUSER=closegap-api | ||
| PGPASSWORD=closegap-api | ||
|
|
||
| PGPORT=5432 |
This file contains hidden or 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,20 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| ROOT=$(git rev-parse --show-toplevel) | ||
|
|
||
| while true; do | ||
| read -p "Seed database with initial data? [Y/n] " yn | ||
| case $yn in | ||
| "" | [Yy]* ) SUFFIX="_seeded"; break;; | ||
| [Nn]* ) SUFFIX=""; break;; | ||
| * ) echo "Please answer y or n.";; | ||
| esac | ||
| done | ||
|
|
||
| createuser -d closegap-api | ||
|
|
||
| createdb -U closegap-api closegap-api_development | ||
| createdb -U closegap-api closegap-api_test | ||
|
|
||
| psql closegap-api_development < ${ROOT}/api/schema/db/development${SUFFIX}.sql | ||
| psql closegap-api_test < ${ROOT}/api/schema/db/test${SUFFIX}.sql | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.