'use strict';

/**
 * Older databases may have a `uom` table without `uom_description`
 * (e.g. manual schema or pre-migration). The Sequelize UOM model expects it.
 */
module.exports = {
  async up(queryInterface, Sequelize) {
    const tableDescription = await queryInterface.describeTable('uom');
    if (!tableDescription.uom_description) {
      await queryInterface.addColumn('uom', 'uom_description', {
        type: Sequelize.STRING(500),
        allowNull: true
      });
    }
  },

  async down(queryInterface) {
    const tableDescription = await queryInterface.describeTable('uom');
    if (tableDescription.uom_description) {
      await queryInterface.removeColumn('uom', 'uom_description');
    }
  }
};
