Last active
July 29, 2020 01:47
-
-
Save derduskenga/46c731549536c8281ec17e4bcdf442b5 to your computer and use it in GitHub Desktop.
decoded app - setting up node app
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
'use strict'; | |
module.exports = { | |
up: async (queryInterface, Sequelize) => { | |
await queryInterface.createTable('Users', { | |
id: { | |
allowNull: false, | |
autoIncrement: true, | |
primaryKey: true, | |
type: Sequelize.INTEGER | |
}, | |
name: { | |
type: Sequelize.STRING | |
}, | |
email: { | |
type: Sequelize.STRING | |
}, | |
createdAt: { | |
allowNull: false, | |
type: Sequelize.DATE | |
}, | |
updatedAt: { | |
allowNull: false, | |
type: Sequelize.DATE | |
} | |
}); | |
}, | |
down: async (queryInterface, Sequelize) => { | |
await queryInterface.dropTable('Users'); | |
} | |
}; |
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
'use strict'; | |
const { | |
Model | |
} = require('sequelize'); | |
module.exports = (sequelize, DataTypes) => { | |
class User extends Model { | |
/** | |
* Helper method for defining associations. | |
* This method is not a part of Sequelize lifecycle. | |
* The `models/index` file will call this method automatically. | |
*/ | |
static associate(models) { | |
// define association here | |
User.hasMany(models.Post); | |
} | |
}; | |
User.init({ | |
name: DataTypes.STRING, | |
email: DataTypes.STRING | |
}, { | |
sequelize, | |
modelName: 'User', | |
}); | |
return User; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment