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

module.exports = {
  async up(queryInterface) {
    await queryInterface.createTable("matching_pairs", {
      ID_MATCHING_PAIRS: {
        type: Sequelize.UUID,
        primaryKey: true,
        defaultValue: Sequelize.UUIDV4,
        allowNull: false,
      },
      ID_ADMIN_EXERCISE: {
        type: Sequelize.UUID,
        allowNull: false,
      },
      LEFT_PAIR: {
        type: Sequelize.TEXT,
        allowNull: true,
      },
      RIGHT_PAIR: {
        type: Sequelize.TEXT,
        allowNull: true,
      },
      TIME_MATCHING_PAIRS: {
        type: Sequelize.DATE,
        allowNull: true,
        defaultValue: Sequelize.NOW,
      },
    });

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

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