Ran npx sequelize-cli db:migrate to migrate.
Created
January 8, 2021 04:34
-
-
Save vickean/9d19fab10024e52a44716b69d5622091 to your computer and use it in GitHub Desktop.
Migration to add apiKey field
This file contains hidden or 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) => { | |
| /** | |
| * Add altering commands here. | |
| * | |
| * Example: | |
| * await queryInterface.createTable('users', { id: Sequelize.INTEGER }); | |
| */ | |
| return queryInterface.sequelize.transaction((t) => { | |
| return Promise.all([ | |
| queryInterface.addColumn("providers", "apiKey", { | |
| allowNull: true, | |
| type: Sequelize.STRING(50), | |
| }), | |
| ]); | |
| }); | |
| }, | |
| down: async (queryInterface, Sequelize) => { | |
| /** | |
| * Add reverting commands here. | |
| * | |
| * Example: | |
| * await queryInterface.dropTable('users'); | |
| */ | |
| return queryInterface.sequelize.transaction((t) => { | |
| return Promise.all([ | |
| queryInterface.removeColumn("providers", "apiKey", { transaction: t }), | |
| ]); | |
| }); | |
| }, | |
| }; |
This file contains hidden or 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 provider 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 | |
| } | |
| } | |
| provider.init( | |
| { | |
| name: { | |
| allowNull: false, | |
| type: DataTypes.STRING(50), | |
| }, | |
| url: { | |
| allowNull: true, | |
| type: DataTypes.STRING, | |
| }, | |
| image: { | |
| allowNull: true, | |
| type: DataTypes.STRING, | |
| }, | |
| isVerified: { | |
| type: DataTypes.BOOLEAN, | |
| defaultValue: true, | |
| allowNull: false, | |
| }, | |
| apiKey: { | |
| type: DataTypes.STRING(50), | |
| allowNull: true, | |
| }, | |
| }, | |
| { | |
| sequelize, | |
| modelName: "provider", | |
| } | |
| ); | |
| return provider; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment