Skip to content

Instantly share code, notes, and snippets.

@notgiorgi
Created January 24, 2017 14:48
Show Gist options
  • Save notgiorgi/7276aae5baebb5725799ce0f5b8468f3 to your computer and use it in GitHub Desktop.
Save notgiorgi/7276aae5baebb5725799ce0f5b8468f3 to your computer and use it in GitHub Desktop.
const GSession = require('./schema')
module.exports = {
up(dbService) {
return dbService.createTable(GSession.options.tableName, GSession.schema))
},
down(dbService) {
return dbService.dropTable(Gsession.options.tableName)
}
}
const GSession = require('./schema')
module.exports = sequelize => sequelize.define('GSession', GSession.schema, GSession.options)
const { DataTypes } = require('sequelize')
module.exports = {
schema: {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
autoIncrement: true,
},
start_time: DataTypes.DATE,
end_time: DataTypes.DATE,
is_closed: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
},
options: {
tableName: 'gsessions',
timestamps: false,
},
}
@vincenting
Copy link

Migration files should be immutable while Model schema will be changed anytime. We need to create to new migration file to change db, and then change model directly. So it's not a good idea to share schema between model and migration file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment