const { Sequelize } = require("sequelize");

module.exports = {
  async up(queryInterface) {
    await queryInterface.createTable("admin_exercise", {
      ID_ADMIN_EXERCISE: {
        type: Sequelize.UUID,
        primaryKey: true,
        defaultValue: Sequelize.UUIDV4,
        allowNull: false,
      },
      ID_LEVEL: {
        type: Sequelize.UUID,
        allowNull: false,
      },
      TITLE: {
        type: Sequelize.STRING(100),
        allowNull: false,
      },
      QUESTION: {
        type: Sequelize.TEXT,
        allowNull: false,
      },
      SCORE_WEIGHT: {
        type: Sequelize.INTEGER(11),
        allowNull: false,
        defaultValue: 1,
      },
      QUESTION_TYPE: {
        type: Sequelize.STRING(100),
        allowNull: false,
      },
      AUDIO: {
        type: Sequelize.STRING(1024),
        allowNull: true,
      },
      VIDEO: {
        type: Sequelize.STRING(1024),
        allowNull: true,
      },
      IMAGE: {
        type: Sequelize.STRING(1024),
        allowNull: true,
      },
      IS_DELETED: {
        type: Sequelize.TINYINT(1),
        allowNull: true,
        defaultValue: 0,
      },
      TIME_ADMIN_EXC: {
        type: Sequelize.DATE,
        allowNull: true,
        defaultValue: Sequelize.NOW,
      },
    });

    await queryInterface.addConstraint("admin_exercise", {
      fields: ["ID_LEVEL"],
      type: "foreign key",
      name: "FK_MEMBUTUHKAN",
      references: {
        table: "level",
        field: "ID_LEVEL",
      },
      onUpdate: "CASCADE",
      onDelete: "CASCADE",
    });
  },

  async down(queryInterface) {
    await queryInterface.dropTable("admin_exercise");
  },
};
