/* eslint-disable no-await-in-loop */
import { DataTypes } from 'sequelize';

import { Migration, safeApplyColumnChanges } from '../migrate';

export const up: Migration = async ({ context }) => {
  await safeApplyColumnChanges(context, {
    prices: [
      {
        name: 'quantity_available',
        field: {
          type: DataTypes.INTEGER,
          defaultValue: 0,
          allowNull: false,
        },
      },
      {
        name: 'quantity_sold',
        field: {
          type: DataTypes.INTEGER,
          defaultValue: 0,
          allowNull: false,
        },
      },
      {
        name: 'quantity_limit_per_checkout',
        field: {
          type: DataTypes.INTEGER,
          defaultValue: 0,
          allowNull: false,
        },
      },
    ],
  });
};

export const down: Migration = async ({ context }) => {
  await context.removeColumn('prices', 'quantity_available');
  await context.removeColumn('prices', 'quantity_sold');
  await context.removeColumn('prices', 'quantity_limit_per_checkout');
};
