'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    // Add lastActivityAt to Customers
    await queryInterface.addColumn('Customers', 'lastActivityAt', {
      type: Sequelize.DATE,
      defaultValue: Sequelize.NOW,
      allowNull: true,
    }).catch(e => console.log('Column lastActivityAt already exists on Customers, skipping.'));

    // Add lastActivityAt to Merchants
    await queryInterface.addColumn('Merchants', 'lastActivityAt', {
      type: Sequelize.DATE,
      defaultValue: Sequelize.NOW,
      allowNull: true,
    }).catch(e => console.log('Column lastActivityAt already exists on Merchants, skipping.'));

    // Add lastActivityAt to Admins
    await queryInterface.addColumn('Admins', 'lastActivityAt', {
      type: Sequelize.DATE,
      defaultValue: Sequelize.NOW,
      allowNull: true,
    }).catch(e => console.log('Column lastActivityAt already exists on Admins, skipping.'));
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.removeColumn('Customers', 'lastActivityAt').catch(() => {});
    await queryInterface.removeColumn('Merchants', 'lastActivityAt').catch(() => {});
    await queryInterface.removeColumn('Admins', 'lastActivityAt').catch(() => {});
  }
};
