'use strict';

module.exports = {
  async up (queryInterface, Sequelize) {
    await queryInterface.createTable('users', {
      id: {
        type: Sequelize.BIGINT,
        autoIncrement: true,
        primaryKey: true,
        allowNull: false
      },
      username: {
        type: Sequelize.STRING,
        field: 'username',
        allowNull: true,
      },
      phoneNumber: {
        type: Sequelize.STRING(20),
        field: 'phone_number',
        allowNull: true
      },
      email: {
        type: Sequelize.STRING(100),
        allowNull: true
      },
      password: Sequelize.STRING,
      active: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: false,
      },
      emailVerificationSentAt: {
        type: Sequelize.DATE,
        field: 'email_verification_sent_at',
      },
      emailVerificationAt: {
        type: Sequelize.DATE,
        field: 'email_verification_at',
      },
      createdAt: {
        type: Sequelize.DATE,
        field: 'created_at',
        allowNull: false,
        defaultValue:Sequelize.fn('NOW'),
      },
      updatedAt: {
        type: Sequelize.DATE,
        field: 'updated_at',
        allowNull: false,
        defaultValue:Sequelize.fn('NOW'),
      },
      deletedAt: {
        type: Sequelize.DATE,
        field: 'deleted_at',
        allowNull: true,
        defaultValue: null
      }
    });

    await queryInterface.addIndex('users', ['email']);
    await queryInterface.addIndex('users', ['phone_number']);
    await queryInterface.addIndex('users', ['active']);
  },

  async down (queryInterface) {
    await queryInterface.dropTable('users');
  }
};
