You can find coveralls repo token
.sample-env
file.
- Development mode:
npm run devStart
- Production mode:
npm run start
Creating migration is done by using createModel
command.
This command takes two parameters:
Name
: the name of the modelattributes
: the list of the model attributes.
To create a model named User
we have to run:
npm run createModel -- --name User --attributes Name:string,Email:string
This will:
- Create a model file
user
in models folder; - Create a migration file with name like
{time-stamp}-create-user.js
in migrations folder.
Even though we created a model it is not inserted into the database yet. So to do that we have to run this command:
npm run migrate
This command will create empty Users
table in the database
You have to execute this command:
npm run migrate-undo
In order to insert data into the table created from migration, you have to create a seed. To create a seed you have to run this command:
npm run createSeed -- --name example-user
this will create a file called {time-stamp}-example-user.js
in the seeders
folder.
So you have to edit it putting in you schema data for a table. The file will that looks like this:
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.bulkInsert('Users', [{
firstName: 'John',
lastName: 'Doe',
email: 'demo@demo.com'
}], {});
},
down: (queryInterface, Sequelize) => {
return queryInterface.bulkDelete('Users', null, {});
}
};
Here in this file you will have to change data as you want before running the seed.
we have created a seed file and we have to commit it to the database.
npm run seed
undoing the seeds we have to run this code:
npm run seed-undo
This will undo the recent seed. To undo all seeds we have to run this:
npm run seed-undo-all
This will undo all seeds committed to the database.