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

module.exports = {
  async up(queryInterface) {
    await queryInterface.createTable("users", {
      ID: {
        type: Sequelize.UUID,
        primaryKey: true,
        defaultValue: Sequelize.UUIDV4,
        allowNull: false,
      },
      NAME_USERS: {
        type: Sequelize.STRING(100),
        allowNull: false,
      },
      EMAIL: {
        type: Sequelize.STRING(100),
        allowNull: false,
      },
      PASSWORD: {
        type: Sequelize.STRING(100),
        allowNull: false,
      },
      ROLE: {
        type: Sequelize.STRING(100),
        allowNull: true,
      },
      PICTURE: {
        type: Sequelize.STRING(1024),
        allowNull: true,
      },
      IS_VALIDATED: {
        type: Sequelize.TINYINT(1),
        allowNull: true,
        defaultValue: 0,
      },
      REFRESH_TOKEN: {
        type: Sequelize.STRING(256),
        allowNull: true,
      },
      TIME_USERS: {
        type: Sequelize.DATE,
        defaultValue: Sequelize.NOW,
      },
    });

    await queryInterface.addConstraint("users", {
      fields: ["EMAIL"],
      type: "unique",
      name: "user_unique_email",
    });
  },
  async down(queryInterface) {
    await queryInterface.dropTable("users");
  },
};
