From 60c5d764b51c248f2d9eaff2ded7a768797b55c6 Mon Sep 17 00:00:00 2001 From: Ashvary Date: Fri, 7 Aug 2020 21:01:08 +0530 Subject: [PATCH] difficulty interger to enum --- ...20200806170752-removeDifficultyFromQuestion.js | 15 +++++++++++++++ .../20200806170817-addDifficultyToQuestion.js | 14 ++++++++++++++ models/questions.js | 4 ++-- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 migrations/20200806170752-removeDifficultyFromQuestion.js create mode 100644 migrations/20200806170817-addDifficultyToQuestion.js diff --git a/migrations/20200806170752-removeDifficultyFromQuestion.js b/migrations/20200806170752-removeDifficultyFromQuestion.js new file mode 100644 index 0000000..8ff4422 --- /dev/null +++ b/migrations/20200806170752-removeDifficultyFromQuestion.js @@ -0,0 +1,15 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.removeColumn('questions', 'difficulty') + }, + + down: (queryInterface, Sequelize) => { + return queryInterface.addColumn('questions', 'difficulty', { + type: Sequelize.INTEGER(), + allowNull: false, + defaultValue: 0 + }) + } +}; diff --git a/migrations/20200806170817-addDifficultyToQuestion.js b/migrations/20200806170817-addDifficultyToQuestion.js new file mode 100644 index 0000000..fb5d073 --- /dev/null +++ b/migrations/20200806170817-addDifficultyToQuestion.js @@ -0,0 +1,14 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.addColumn('questions', 'difficulty', { + type: Sequelize.ENUM('EASY', 'MEDIUM', 'HARD'), + allowNull: false, + }) + }, + + down: (queryInterface, Sequelize) => { + return queryInterface.removeColumn('questions', 'difficulty') + } +}; \ No newline at end of file diff --git a/models/questions.js b/models/questions.js index 10011c9..c6df6c1 100644 --- a/models/questions.js +++ b/models/questions.js @@ -14,9 +14,9 @@ module.exports = (sequelize, DataTypes) => { allowNull: true }, difficulty: { - type: DataTypes.INTEGER, + type: DataTypes.ENUM ('EASY', 'MEDIUM', 'HARD'), allowNull: false, - defaultValue: 0 + defaultValue: 'EASY' }, correctAnswers: { type: DataTypes.ARRAY(DataTypes.BIGINT),