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

module.exports = {
  async up(queryInterface) {
    await queryInterface.createTable("topic", {
      ID_TOPIC: {
        type: Sequelize.UUID,
        primaryKey: true,
        defaultValue: Sequelize.UUIDV4,
        allowNull: false,
      },
      ID_SECTION: {
        type: Sequelize.UUID,
        allowNull: false,
      },
      NAME_TOPIC: {
        type: Sequelize.STRING(100),
        allowNull: false,
      },
      DESCRIPTION_TOPIC: {
        type: Sequelize.TEXT,
        allowNull: true,
      },
      IS_DELETED: {
        type: Sequelize.TINYINT(1),
        allowNull: true,
        defaultValue: 0,
      },
      TIME_TOPIC: {
        type: Sequelize.DATE,
        allowNull: true,
        defaultValue: Sequelize.NOW,
      },
    });

    await queryInterface.addConstraint("topic", {
      fields: ["ID_SECTION"],
      type: "foreign key",
      name: "FK_MEMILIKI",
      references: {
        table: "section",
        field: "ID_SECTION",
      },
      onUpdate: "CASCADE",
      onDelete: "CASCADE",
    });
  },

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