Skip to content

Instantly share code, notes, and snippets.

@derduskenga
Last active July 29, 2020 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derduskenga/46c731549536c8281ec17e4bcdf442b5 to your computer and use it in GitHub Desktop.
Save derduskenga/46c731549536c8281ec17e4bcdf442b5 to your computer and use it in GitHub Desktop.
decoded app - setting up node app
'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');
}
};
'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