- "dotenv": "^8.2.0"
- "express": "^4.17.1"
- "pg": "^8.0.3"
- "pg-hstore": "^2.3.3"
- "sequelize": "^5.21.7"
- "sequelize-cli": "^5.5.1"
npm i
- Delete
database
folder and runsequelize init
to initialize.sequelize
file. - Modify the
database/config/config.js
file like so:
"development": {
"url": process.env.DEV_DB_URL,
"dialect": "postgres"
}
Note: Modify other envs as well.
- Modify
models/index.js
file like so.
let sequelize;
if (config.url) {
sequelize = new Sequelize(config.url);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
- Create
models
andmigrations
using command:
sequelize model:generate --name <model_name> --attributes <attributes>
E.g.:sequelize model:generate --name User --attributes name:string,email:string
- Modify the respective model files. Add their associations.
- Edit/Create the .env file
- Run the command:
sequelize db:migrate
to create tables in the database.