Skip to content

Commit

Permalink
Jma/cu 29p9ce3 fix heroku deployment waterloop cms (#7)
Browse files Browse the repository at this point in the history
* Minimize babel modules and update script knexfile path

* Move migration + seed + knexfile to src/backend
  • Loading branch information
Jeff Ma authored May 19, 2022
1 parent 9066156 commit ab7ad19
Show file tree
Hide file tree
Showing 34 changed files with 511 additions and 415 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Content on our main website is being constantly added and updated on a term-by-t

0. Ensure you have `node v16`, `yarn v1.*` and `Docker Desktop` installed. See onboarding docs for more info.
1. Install dependencies with `yarn install --frozen-lockfile`
2. Start the backend by running `yarn docker:dev`, then by running `yarn dev`
3. Launch the frontend with `yarn start`
2. Start the backend by running `yarn docker:dev`, then open a new terminal and run `yarn dev`
3. Launch the frontend in a new terminal with `yarn start:frontend`

## 💻 Technologies

Expand Down
12 changes: 0 additions & 12 deletions migrations/20210613140510_feature_permissions.js

This file was deleted.

96 changes: 47 additions & 49 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,72 @@
"node": "=16.*",
"yarn": "=1.*"
},
"scripts": {
"start:frontend": "cross-env PORT=3000 react-scripts start",
"build:frontend": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook -s public",
"test:unit": "cross-env NODE_ENV=test cross-env PORT=9000 mocha -r esm ./src/backend/tests/unit/*",
"test:integration": "cross-env NODE_ENV=test cross-env PORT=9000 mocha -r esm --exit ./src/backend/tests/integration/*",
"test:integration:specific": "cross-env NODE_ENV=test cross-env PORT=9000 mocha -r esm --exit",
"test:integration:watch": "cross-env NODE_ENV=test cross-env PORT=9000 mocha -r esm --watch ./src/backend/tests/integration/*",
"test:all": "yarn test:unit && yarn test:integration",
"docker:test": "docker-compose run --service-ports test-db ",
"docker:dev": "docker-compose run --service-ports dev-db ",
"dev": "yarn migrate && yarn seed && cross-env NODE_ENV=development nodemon --exec ./node_modules/.bin/babel-node src/backend/index.js",
"prebuild": "yarn build:frontend && node ./src/backend/scripts/generate-gcp-key.js",
"build": "cross-env NODE_ENV=production babel src/backend --out-dir lib --copy-files",
"start": "cross-env NODE_ENV=production babel-node lib/index.js",
"deploy": "git push heroku main",
"migrate": "knex migrate:latest --knexfile src/backend/knexfile.js",
"seed:dev": "cross-env NODE_ENV=development knex seed:run",
"seed": "knex seed:run --knexfile src/backend/knexfile.js",
"seed:make": "knex seed:make --knexfile src/backend/knexfile.js",
"migrate:make": "knex migrate:make --knexfile src/backend/knexfile.js",
"development:migrate:rollback": "cross-env NODE_ENV=development knex migrate:rollback --knexfile src/backend/knexfile.js",
"production:migrate:rollback": "cross-env NODE_ENV=production knex migrate:rollback",
"production:migrate:latest": "cross-env NODE_ENV=production knex migrate:latest",
"production:seed": "cross-env NODE_ENV=production knex seed:run",
"test:migrate:rollback": "cross-env NODE_ENV=test knex migrate:rollback --knexfile src/backend/knexfile.js",
"test:migrate:latest": "cross-env NODE_ENV=test knex migrate:latest --knexfile src/backend/knexfile.js",
"test:seed": "cross-env NODE_ENV=test knex seed:run --knexfile src/backend/knexfile.js"
},
"dependencies": {
"@babel/node": "^7.17.10",
"@google-cloud/storage": "^5.7.4",
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.11.2",
"@mui/icons-material": "^5.3.1",
"@mui/material": "^5.4.0",
"@google-cloud/storage": "^5.7.4",
"axios": "^0.21.2",
"draft-convert": "^2.1.11",
"draft-js": "^0.11.7",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"csurf": "^1.11.0",
"dotenv": "^8.2.0",
"draft-convert": "^2.1.11",
"draft-js": "^0.11.7",
"express": "^4.17.1",
"express-pg-session": "^1.1.0",
"express-session": "^1.17.1",
"express-validator": "^6.6.1",
"form-data": "^4.0.0",
"google-auth-library": "^7.0.3",
"googleapis": "^79.0.0",
"knex": "^0.21.5",
"md5": "^2.3.0",
"dotenv": "^8.2.0",
"form-data": "^4.0.0",
"moment": "^2.29.2",
"multer": "^1.4.2",
"nodemon": "^2.0.4",
"pg": "^8.5.1",
"pg-connection-string": "^2.4.0",
"postgres": "^1.0.2",
"ramda": "^0.27.1",
"socket.io": "^2.4.1",
"react": "^16.13.1",
"react-datepicker": "^3.5.0",
"react-dom": "^16.13.1",
Expand All @@ -49,44 +83,11 @@
"react-scripts": "3.4.3",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"socket.io": "^2.4.1",
"socket.io-client": "2.3.0",
"styled-components": "^5.2.1",
"typeface-ibm-plex-sans": "^1.1.13"
},
"scripts": {
"start:frontend": "cross-env PORT=3000 react-scripts start",
"build:frontend": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook -s public",
"test:unit": "cross-env NODE_ENV=test cross-env PORT=9000 mocha -r esm ./src/backend/tests/unit/*",
"test:integration": "cross-env NODE_ENV=test cross-env PORT=9000 mocha -r esm --exit ./src/backend/tests/integration/*",
"test:integration:specific": "cross-env NODE_ENV=test cross-env PORT=9000 mocha -r esm --exit",
"test:integration:watch": "cross-env NODE_ENV=test cross-env PORT=9000 mocha -r esm --watch ./src/backend/tests/integration/*",
"test:all": "yarn test:unit && yarn test:integration",
"docker:test": "docker-compose run --service-ports test-db ",
"docker:dev": "docker-compose run --service-ports dev-db ",
"dev": "yarn migrate && yarn seed && cross-env NODE_ENV=development nodemon --exec ./node_modules/.bin/babel-node src/backend/index.js",
"prebuild": "yarn build:frontend && node ./src/backend/scripts/generate-gcp-key.js",
"build": "cross-env NODE_ENV=production babel src/backend --out-dir lib --copy-files",
"start": "cross-env NODE_ENV=production babel-node lib/index.js",
"deploy": "git push heroku main",
"migrate": "knex migrate:latest ",
"seed:dev": "cross-env NODE_ENV=development knex seed:run",
"seed": "knex seed:run",
"seed:make": "knex seed:make",
"migrate:make": "knex migrate:make",
"development:migrate:rollback": "cross-env NODE_ENV=development knex migrate:rollback",
"production:migrate:rollback": "cross-env NODE_ENV=production knex migrate:rollback",
"production:migrate:latest": "cross-env NODE_ENV=production knex migrate:latest",
"production:seed": "cross-env NODE_ENV=production knex seed:run",
"test:migrate:rollback": "cross-env NODE_ENV=test knex migrate:rollback",
"test:migrate:latest": "cross-env NODE_ENV=test knex migrate:latest",
"test:seed": "cross-env NODE_ENV=test knex seed:run"
},
"browserslist": {
"production": [
">0.2%",
Expand All @@ -100,11 +101,9 @@
]
},
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/eslint-parser": "^7.11.5",
"@babel/node": "^7.10.5",
"@babel/preset-env": "^7.11.5",
"@babel/register": "^7.12.10",
"@babel/cli": "^7.17.10",
"@babel/core": "^7.17.12",
"@babel/preset-env": "^7.17.12",
"@storybook/addon-actions": "^6.1.11",
"@storybook/addon-essentials": "^6.1.11",
"@storybook/addon-links": "^6.1.11",
Expand All @@ -114,13 +113,12 @@
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"babel-loader": "8.1.0",
"cross-env": "^7.0.3",
"esm": "^3.2.25",
"mocha": "^8.2.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.12.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-prettier": "^3.1.4"
"eslint-plugin-prettier": "^3.1.4",
"esm": "^3.2.25",
"mocha": "^8.2.0"
}
}
2 changes: 1 addition & 1 deletion src/backend/db/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const connection = require('../../../knexfile')[process.env.NODE_ENV || 'test']; // TODO - Fix this
const connection = require('../knexfile')[process.env.NODE_ENV || 'test'];
export const db = require('knex')(connection);
import users from './users';
import teamDescriptors from './team-descriptors';
Expand Down
2 changes: 1 addition & 1 deletion src/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ if (process.env.NODE_ENV !== 'production') {
}

/* These need to be the last routes */
app.use(express.static('./frontend/build'));
app.use(express.static('./build'));
app.get('*', (req, res) => {
res.sendFile('index.html', { root: path.join(__dirname, '../../build') });
});
Expand Down
37 changes: 21 additions & 16 deletions knexfile.js → src/backend/knexfile.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

require('dotenv').config();
const path = require('path');
// Update with your config settings.
let config;
if (process.env.NODE_ENV === 'production') {
const { parse } = require('pg-connection-string');
config = parse(process.env.DATABASE_URL);
// NOTE: Comment this out if you're testing the production environment on a local postgres database!
config.ssl = {
rejectUnauthorized: false
rejectUnauthorized: false,
};
}

Expand All @@ -17,44 +17,48 @@ module.exports = {
connection: 'postgresql://docker:docker@localhost:5434',
useNullAsDefault: true,
migrations: {
tableName: 'knex_migrations'
}
tableName: 'knex_migrations',
},
},
test: {
client: 'pg',
connection: 'postgresql://docker:docker@localhost:5454',
useNullAsDefault: true,
migrations: {
tableName: 'knex_migrations'
}
tableName: 'knex_migrations',
directory: path.join(__dirname, './migrations'),
},
seeds: {
directory: path.join(__dirname, './seeds'),
},
},

staging: {
client: 'postgresql',
connection: {
database: 'my_db',
user: 'username',
password: 'password'
password: 'password',
},
pool: {
min: 2,
max: 10
max: 10,
},
migrations: {
tableName: 'knex_migrations'
}
tableName: 'knex_migrations',
},
},

production: {
client: 'postgresql',
connection: config,
pool: {
min: 2,
max: 10
max: 10,
},
migrations: {
tableName: 'knex_migrations'
}
tableName: 'knex_migrations',
},
},

/**KNEX-specific custom utility functions */
Expand All @@ -65,11 +69,12 @@ module.exports = {
* Required since knex.js doesn't have this functionality built in.
* Uses SQLite or Postgres trigger statements depending on the environment.
*/
onUpdateTrigger: (table) =>
`CREATE TRIGGER ${table}_updated_at
onUpdateTrigger: (table) =>
`CREATE TRIGGER ${table}_updated_at
BEFORE UPDATE ON ${table}
FOR EACH ROW
EXECUTE PROCEDURE on_update_timestamp()
`,
ENV_IS_STAGING_OR_PROD: process.env.NODE_ENV === 'production' || process.env.NODE_ENV === "staging",
ENV_IS_STAGING_OR_PROD:
process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging',
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions src/backend/migrations/20210613140510_feature_permissions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
exports.up = async (knex) =>
knex.schema.createTable('feature_permissions', (table) => {
table.string('id').primary(); // P-key
table.string('group_id'); // F-key
table.string('feature_name');

table.foreign('group_id').references('groups.id').onDelete('CASCADE');
});

exports.down = async function (knex) {
await knex.schema.hasTable('groups', (table) => {
table.dropForeign('group_id');
});
return knex.schema.dropTableIfExists('feature_permissions');
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { ENV_IS_STAGING_OR_PROD } = require('../knexfile');
const { parseTimeFromRequest } = require('../src/backend/utils/db-dates');
const { parseTimeFromRequest } = require('../utils/db-dates');

if (!ENV_IS_STAGING_OR_PROD) {
exports.seed = function (knex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { ENV_IS_STAGING_OR_PROD } = require('../knexfile');
const { parseTimeFromRequest } = require('../src/backend/utils/db-dates');
const { parseTimeFromRequest } = require('../utils/db-dates');

if (!ENV_IS_STAGING_OR_PROD) {
exports.seed = function (knex) {
Expand Down
2 changes: 1 addition & 1 deletion seeds/06_groups.js → src/backend/seeds/06_groups.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { ENV_IS_STAGING_OR_PROD } = require('../knexfile');
const { parseTimeFromRequest } = require('../src/backend/utils/db-dates');
const { parseTimeFromRequest } = require('../utils/db-dates');

// An issue with deploying is that we require this seeding for the functionality on the actual deployment.
// A new table that is deployed needs to be migrated the first time its deployed, then, in order to avoid this, we would put the !ENV_IS_STAGING_OR_PROD checker again?
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const R = require('ramda');
const { ENV_IS_STAGING_OR_PROD } = require('../knexfile');
const { parseTimeFromRequest } = require('../src/backend/utils/db-dates');
const { parseTimeFromRequest } = require('../utils/db-dates');

const Posting = (id, date, team_id) => ({
title: 'Front End developer',
Expand Down
Loading

0 comments on commit ab7ad19

Please sign in to comment.