Skip to content

Commit

Permalink
Cria Models e Seeders
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemuller20 committed Dec 7, 2021
1 parent ae2890b commit 3d3f990
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion migrations/20211207130602-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
primaryKey: true,
type: Sequelize.INTEGER,
},
name: {
username: {
allowNull: false,
type: Sequelize.STRING,
},
Expand Down
13 changes: 13 additions & 0 deletions models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = (sequelize, DataTypes) => {
const User = sequelize.define('User', {
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
username: DataTypes.STRING,
password: DataTypes.STRING,
},
{
timestamps: false,
tableName: 'Users',
});

return User;
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"main": "./api/server.js",
"scripts": {
"prestart": "npx sequelize-cli db:create && npx sequelize-cli db:migrate $",
"dev": "nodemon ."
},
"dependencies": {
Expand Down
20 changes: 20 additions & 0 deletions seeders/20211207131858-users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
up: async (queryInterface, _Sequelize) => {
await queryInterface.bulkInsert('Users',
[{
id: 1,
username: 'Raul Seixas',
password: 'tocaraul',
},
{
id: 2,
username: 'Cássia Eller',
password: 'relicario',
},
], { timestamps: false });
},

down: async (queryInterface, _Sequelize) => {
await queryInterface.bulkDelete('Users', null, {});
},
};

0 comments on commit 3d3f990

Please sign in to comment.