Last active
June 3, 2019 09:14
-
-
Save warrenlalata/d11b2f76f9ef8b3ce12fd291bf2d3534 to your computer and use it in GitHub Desktop.
Steps to configure Sequelize ORM to work with Node Backend
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
# Development | |
DEV_DB_USERNAME=root | |
DEV_DB_PASSWORD=yourdbpassword | |
DEV_DB_NAME=apollo_development | |
DEV_DB_HOSTNAME=localhost | |
# Test | |
TEST_DB_USERNAME=root | |
TEST_DB_PASSWORD=yourdbpassword | |
TEST_DB_NAME=apollo_development | |
TEST_DB_HOSTNAME=localhost | |
# Prod | |
PROD_DB_USERNAME=root | |
PROD_DB_PASSWORD=yourdbpassword | |
PROD_DB_NAME=apollo_production | |
PROD_DB_HOSTNAME=localhost |
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 overrides the default path to migrations, models, seeders or config folder. | |
const path = require('path'); | |
module.exports = { | |
'config': path.resolve('config', 'config.js'), | |
'models-path': path.resolve('db', 'models'), | |
'seeders-path': path.resolve('db', 'seeders'), | |
'migrations-path': path.resolve('db', 'migrations') | |
} |
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
require('dotenv').config() | |
module.exports = { | |
development: { | |
username: process.env.DEV_DB_USERNAME, | |
password: process.env.DEV_DB_PASSWORD, | |
database: process.env.DEV_DB_NAME, | |
host: process.env.DEV_DB_HOSTNAME, | |
dialect: 'postgres' | |
}, | |
test: { | |
username: process.env.TEST_DB_USERNAME, | |
password: process.env.TEST_DB_PASSWORD, | |
database: process.env.TEST_DB_NAME, | |
host: process.env.TEST_DB_HOSTNAME, | |
dialect: 'postgres' | |
}, | |
production: { | |
username: process.env.PROD_DB_USERNAME, | |
password: process.env.PROD_DB_PASSWORD, | |
database: process.env.PROD_DB_NAME, | |
host: process.env.PROD_DB_HOSTNAME, | |
dialect: 'postgres' | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yarn sequelize init
after.yarn add dotenv
.config.js
.env.sample
into your .env and change the values.To create the database, run:
$ yarn sequelize db:create
To drop the database, run:
$ yarn sequelize db:create
NOTE:
When using production databse in Heroku, add the code below after dialect property on the config js. See: https://stackoverflow.com/questions/27687546/cant-connect-to-heroku-postgresql-database-from-local-node-app-with-sequelize
dialectOptions: {
ssl: true
}