Skip to content

Commit

Permalink
completed heroku deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
psychicbologna committed Nov 24, 2019
1 parent bc23bb5 commit 7d207fa
Show file tree
Hide file tree
Showing 20 changed files with 5,026 additions and 4,827 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
.env
node_modules
.env
168 changes: 84 additions & 84 deletions README.md
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.
16 changes: 8 additions & 8 deletions migrations/001.do.create_noteful_folders.sql
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
);
2 changes: 1 addition & 1 deletion migrations/001.undo.create_noteful_folders.sql
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";
28 changes: 14 additions & 14 deletions migrations/002.do.create_noteful_notes.sql
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;
6 changes: 3 additions & 3 deletions migrations/002.undo.create_noteful_notes.sql
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;
12 changes: 6 additions & 6 deletions migrations/003.do.create_noteful_folder_notes.sql
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)
)
Loading

0 comments on commit 7d207fa

Please sign in to comment.