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

module.exports = {
  async up(queryInterface) {
    await queryInterface.createTable("teacher", {
      ID_GURU: {
        type: Sequelize.UUID,
        primaryKey: true,
        defaultValue: Sequelize.UUIDV4,
        allowNull: false,
      },
      ID: {
        type: Sequelize.UUID,
        allowNull: false,
      },
      NIP: {
        type: Sequelize.BIGINT(11),
        allowNull: false,
      },
    });

    await queryInterface.addConstraint("teacher", {
      fields: ["NIP"],
      type: "unique",
      name: "teacher_unique_nip",
    });

    await queryInterface.addConstraint("teacher", {
      fields: ["ID"],
      type: "foreign key",
      name: "FK_MERANGKAP",
      references: {
        table: "users",
        field: "ID",
      },
      onUpdate: "CASCADE",
      onDelete: "CASCADE",
    });
  },

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