Skip to content

Instantly share code, notes, and snippets.

@allaniftrue
Created August 9, 2018 17:25
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 allaniftrue/9bb312a568eed5aff94b8cf9ad9d679c to your computer and use it in GitHub Desktop.
Save allaniftrue/9bb312a568eed5aff94b8cf9ad9d679c to your computer and use it in GitHub Desktop.
A sample sequelize migration with default value for timestamps
"use strict";
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable("users", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
first_name: {
allowNull: false,
type: Sequelize.STRING
},
last_name: {
allowNull: false,
type: Sequelize.STRING
},
email: {
allowNull: false,
type: Sequelize.STRING
},
password: {
allowNull: false,
type: Sequelize.STRING
},
is_confirmed: {
allowNull: false,
type: Sequelize.BOOLEAN,
defaultValue: false
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal("NOW()")
},
updated_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal("NOW()")
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable("users");
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment