-
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.
- Loading branch information
1 parent
bc23bb5
commit 7d207fa
Showing
20 changed files
with
5,026 additions
and
4,827 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
node_modules | ||
.env | ||
node_modules | ||
.env |
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 |
---|---|---|
@@ -1,84 +1,84 @@ | ||
# Noteful App | ||
|
||
Whoopee. | ||
|
||
## Process | ||
|
||
### Server Set-Up | ||
|
||
- Run expressclone. | ||
- Create dbs | ||
- Install pg and postgrator-cli (devDependency) for SQL migration | ||
- Install knex and xss for testing and server utility. | ||
- Update .env with DB and TESTDB URLs. (postgresql://localhost/username@dbname) | ||
- Modify server.js to require knex and create the const `db`, which establishes a client (pg) and connection (DB_URL) for knex. Call DB_URL from `require('./config')` and inject into app with `app.set` before the listen: | ||
|
||
```javascript | ||
const knex = require('knex'); | ||
... | ||
const { PORT, DB_URL } = require('./config'); | ||
|
||
const db = knex({ | ||
client: 'pg', | ||
connection: DB_URL | ||
}); | ||
|
||
app.set('db', db); | ||
... | ||
|
||
``` | ||
|
||
- Write `postgrator-config.js` | ||
|
||
```javascript | ||
require('dotenv').config(); | ||
|
||
module.exports = { | ||
"migrationsDirectory": "migrations", | ||
"driver": "pg", | ||
"connectionString": (process.env.NODE_ENV === 'test') | ||
? process.env.TEST_DB_URL | ||
: process.env.DB_URL, | ||
}; | ||
``` | ||
|
||
- Update package.json scripts with migrate and migrate:test. | ||
|
||
`"migrate": "postgrator --config postgrator-config.js",` | ||
|
||
`"migrate:test": "env NODE_ENV=test npm run migrate",` | ||
|
||
### DB Design and Migration | ||
|
||
- Sketch ERD structure. Consider foreign key constraints, normalizing, one-to-many vs. many-to-many. Do I need a relationship table? Do I need to alter tables for foreign references? | ||
- Write initial migrations to create tables. Iterate to test out your database ERD. | ||
- Write a seed file following the structure to run tests with down the road (can you pull this from front end?). | ||
|
||
### Service Objects | ||
|
||
- Create directories and NAME-service.js files for each object. | ||
- Determine necessary CRUD operations and write functions that will interact as expected with the database. | ||
|
||
### Routers | ||
|
||
- Add NAME-router.js files for each directory (In my bash, I wrote a script (routerreq NAME), which generates a `NAME-router.js` file with all the required constants). Create `NAME-endpoints.spec.js` and `NAME.fixtures.js` files in test directory for each object. | ||
|
||
```javascript | ||
const express = require('express'), | ||
xss = require('xss'), | ||
FoldersService = require('./folders-service'), | ||
foldersRouter = express.Router(), | ||
jsonParser = express.json(); | ||
``` | ||
|
||
## Scripts | ||
|
||
Start the application `npm start` | ||
|
||
Start nodemon for the application `npm run dev` | ||
|
||
Run the tests `npm test` | ||
|
||
## Deploying | ||
|
||
When your new project is ready for deployment, add a new Heroku application with `heroku create`. This will make a new git remote called "heroku" and you can then `npm run deploy` which will push to this remote's master branch. | ||
# Noteful App | ||
|
||
Whoopee. | ||
|
||
## Process | ||
|
||
### Server Set-Up | ||
|
||
- Run expressclone. | ||
- Create dbs | ||
- Install pg and postgrator-cli (devDependency) for SQL migration | ||
- Install knex and xss for testing and server utility. | ||
- Update .env with DB and TESTDB URLs. (postgresql://localhost/username@dbname) | ||
- Modify server.js to require knex and create the const `db`, which establishes a client (pg) and connection (DB_URL) for knex. Call DB_URL from `require('./config')` and inject into app with `app.set` before the listen: | ||
|
||
```javascript | ||
const knex = require('knex'); | ||
... | ||
const { PORT, DB_URL } = require('./config'); | ||
|
||
const db = knex({ | ||
client: 'pg', | ||
connection: DB_URL | ||
}); | ||
|
||
app.set('db', db); | ||
... | ||
|
||
``` | ||
|
||
- Write `postgrator-config.js` | ||
|
||
```javascript | ||
require('dotenv').config(); | ||
|
||
module.exports = { | ||
"migrationsDirectory": "migrations", | ||
"driver": "pg", | ||
"connectionString": (process.env.NODE_ENV === 'test') | ||
? process.env.TEST_DB_URL | ||
: process.env.DB_URL, | ||
}; | ||
``` | ||
|
||
- Update package.json scripts with migrate and migrate:test. | ||
|
||
`"migrate": "postgrator --config postgrator-config.js",` | ||
|
||
`"migrate:test": "env NODE_ENV=test npm run migrate",` | ||
|
||
### DB Design and Migration | ||
|
||
- Sketch ERD structure. Consider foreign key constraints, normalizing, one-to-many vs. many-to-many. Do I need a relationship table? Do I need to alter tables for foreign references? | ||
- Write initial migrations to create tables. Iterate to test out your database ERD. | ||
- Write a seed file following the structure to run tests with down the road (can you pull this from front end?). | ||
|
||
### Service Objects | ||
|
||
- Create directories and NAME-service.js files for each object. | ||
- Determine necessary CRUD operations and write functions that will interact as expected with the database. | ||
|
||
### Routers | ||
|
||
- Add NAME-router.js files for each directory (In my bash, I wrote a script (routerreq NAME), which generates a `NAME-router.js` file with all the required constants). Create `NAME-endpoints.spec.js` and `NAME.fixtures.js` files in test directory for each object. | ||
|
||
```javascript | ||
const express = require('express'), | ||
xss = require('xss'), | ||
FoldersService = require('./folders-service'), | ||
foldersRouter = express.Router(), | ||
jsonParser = express.json(); | ||
``` | ||
|
||
## Scripts | ||
|
||
Start the application `npm start` | ||
|
||
Start nodemon for the application `npm run dev` | ||
|
||
Run the tests `npm test` | ||
|
||
## Deploying | ||
|
||
When your new project is ready for deployment, add a new Heroku application with `heroku create`. This will make a new git remote called "heroku" and you can then `npm run deploy` which will push to this remote's master branch. |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
DROP TABLE IF EXISTS folders; | ||
DROP EXTENSION IF EXISTS "uuid-ossp"; | ||
|
||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; | ||
|
||
CREATE TABLE folders ( | ||
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
name TEXT NOT NULL | ||
DROP TABLE IF EXISTS folders; | ||
DROP EXTENSION IF EXISTS "uuid-ossp"; | ||
|
||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; | ||
|
||
CREATE TABLE folders ( | ||
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
name TEXT NOT NULL | ||
); |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
DROP TABLE IF EXISTS folders; | ||
DROP TABLE IF EXISTS folders; | ||
DROP EXTENSION IF EXISTS "uuid-ossp"; |
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
DROP TABLE IF EXISTS notes; | ||
|
||
CREATE TABLE notes ( | ||
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
name TEXT NOT NULL, | ||
modified TIMESTAMP DEFAULT now() NOT NULL, | ||
content TEXT NOT NULL | ||
); | ||
|
||
ALTER TABLE | ||
notes | ||
ADD | ||
COLUMN folders_id uuid REFERENCES folders(id) ON DELETE | ||
SET | ||
DROP TABLE IF EXISTS notes; | ||
|
||
CREATE TABLE notes ( | ||
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
name TEXT NOT NULL, | ||
modified TIMESTAMP DEFAULT now() NOT NULL, | ||
content TEXT NOT NULL | ||
); | ||
|
||
ALTER TABLE | ||
notes | ||
ADD | ||
COLUMN folders_id uuid REFERENCES folders(id) ON DELETE | ||
SET | ||
NULL; |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
ALTER TABLE | ||
notes DROP COLUMN folders_id; | ||
|
||
ALTER TABLE | ||
notes DROP COLUMN folders_id; | ||
|
||
DROP TABLE IF EXISTS notes; |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
DROP TABLE IF EXISTS folders_notes; | ||
|
||
CREATE TABLE IF NOT EXISTS folders_notes ( | ||
folders_id uuid REFERENCES folders(id) ON DELETE SET NULL, | ||
notes_id uuid REFERENCES notes(id) ON DELETE SET NULL, | ||
PRIMARY KEY (folders_id, notes_id) | ||
DROP TABLE IF EXISTS folders_notes; | ||
|
||
CREATE TABLE IF NOT EXISTS folders_notes ( | ||
folders_id uuid REFERENCES folders(id) ON DELETE SET NULL, | ||
notes_id uuid REFERENCES notes(id) ON DELETE SET NULL, | ||
PRIMARY KEY (folders_id, notes_id) | ||
) |
Oops, something went wrong.