import { DataTypes } from 'sequelize';

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

export const up: Migration = async ({ context }) => {
  await safeApplyColumnChanges(context, {
    payment_currencies: [
      {
        name: 'maximum_precision',
        field: {
          type: DataTypes.NUMBER,
          allowNull: true,
          defaultValue: 6,
        },
      },
    ],
  });
  const schema = await context.describeTable('payment_links');
  if (schema.maximum_precision) {
    await context.removeColumn('payment_links', 'maximum_precision');
  }
};

export const down: Migration = async ({ context }) => {
  await context.removeColumn('payment_currencies', 'maximum_precision');
};
