'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    const table = 'production_qc';
    const cols = await queryInterface.describeTable(table);

    if (!cols.actual_start) {
      await queryInterface.addColumn(table, 'actual_start', {
        type: Sequelize.DATE,
        allowNull: true,
        after: 'qc_at'
      });
    }

    if (!cols.actual_end) {
      await queryInterface.addColumn(table, 'actual_end', {
        type: Sequelize.DATE,
        allowNull: true,
        after: 'actual_start'
      });
    }
  },

  async down(queryInterface) {
    const table = 'production_qc';
    const cols = await queryInterface.describeTable(table);

    if (cols.actual_end) {
      await queryInterface.removeColumn(table, 'actual_end');
    }
    if (cols.actual_start) {
      await queryInterface.removeColumn(table, 'actual_start');
    }
  }
};
