Skip to content

A basic CRUD app backend created using NestJS, Sequelize, Sequelize-Migration & Swagger for Documentation.

Notifications You must be signed in to change notification settings

kishore007k/nestjs-restapi-sequelize-template

Repository files navigation

NestJs-Sequelize-RestAPI

This is a template for NestJs, which contains Sequelize with postgres Database, sequelize migration and Swagger API Documentation.

How to create Migration:

Open a new terminal and enter the following command npx sequelize-cli migration:generate --name <migration-name> then press Enter.

A migration file will be created inside the database/migration folder.

Example:

npx sequelize-cli migration:generate --name add-firstname

This command will create a migration file inside the database/migration folder with the name 20220415042414-add-firstname with the timestamp at the front.

For more Migration related doubts go to the Sequelize Migration page.

Migration Features:

  1. To run the migration, open a new terminal and enter the command npm run migrate status first to check is there any pending migrations that should be run or not.

  2. Running this command will give you a object with keys ex (executed) and pd (pending).

  3. If there is any Migrations pending enter the following command to migrate npm run migrate up.

  4. to revert all the migrations use npm run migrate down. This will revert all the migration that was ever done.

  5. To run more than one migration at a time use the npm run migrate next, this will run all the migrations.

  6. If there was any error in the previous migration you can undo it by npm run migration prev or npm run migrate reset-prev. This will revert only the last migration.

  7. npm run migrate reset-hard, this will drops and creates a new table with the same name.

About

A basic CRUD app backend created using NestJS, Sequelize, Sequelize-Migration & Swagger for Documentation.

Topics

Resources

Stars

Watchers

Forks