Last active
November 13, 2019 22:00
-
-
Save felipegenuino/c6a05abfaaf6010d50eaa725fafd892c to your computer and use it in GitHub Desktop.
Migrations with sequilize
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
const {resolve} = require('path'); | |
module.exports = { | |
config: resolve(__dirname, 'src', 'database.js'), | |
'models-path': resolve(__dirname, 'src', 'models'), | |
'migrations-path': resolve(__dirname, 'src', 'database', 'migrations'), | |
'seeders-path': resolve(__dirname, 'src', 'database', 'seeds') | |
} |
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: (queryInterface, Sequelize) => { | |
/* | |
Add altering commands here. | |
Return a promise to correctly handle asynchronicity. | |
Example: | |
*/ | |
return queryInterface.createTable('users', { | |
id: { | |
type: Sequelize.INTEGER, | |
allowNull: false, | |
autoIncrement: true, | |
primaryKey: true, | |
}, | |
name: { | |
type: Sequelize.STRING, | |
allowNull: false, | |
}, | |
email: { | |
type: Sequelize.STRING, | |
allowNull: false, | |
unique: true, | |
}, | |
password_hash: { | |
type: Sequelize.STRING, | |
allowNull: false, | |
}, | |
provider: { | |
type: Sequelize.BOOLEAN, | |
defaultValue: false, | |
allowNull: false, | |
}, | |
created_at: { | |
type: Sequelize.DATE, | |
allowNull: false, | |
}, | |
updated_at: { | |
type: Sequelize.DATE, | |
allowNull: false, | |
}, | |
}); | |
}, | |
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
$ yarn add sequelize
$ yarn add sequelize-cli -D
yarn sequelize migration:create --name=create-users
yarn sequelize db:migrate