import { DataTypes } from 'sequelize';

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

export const up: Migration = async ({ context }) => {
  await safeApplyColumnChanges(context, {
    price_quotes: [
      {
        name: 'slippage_percent',
        field: {
          type: DataTypes.DECIMAL(5, 2),
          allowNull: true,
        },
      },
      {
        name: 'max_payable_token',
        field: {
          type: DataTypes.STRING(64),
          allowNull: true,
        },
      },
      {
        name: 'min_acceptable_rate',
        field: {
          type: DataTypes.STRING(32),
          allowNull: true,
        },
      },
      {
        name: 'slippage_derived_at_ms',
        field: {
          type: DataTypes.BIGINT,
          allowNull: true,
        },
      },
    ],
  });
};

export const down: Migration = async ({ context }) => {
  await context.removeColumn('price_quotes', 'slippage_percent');
  await context.removeColumn('price_quotes', 'max_payable_token');
  await context.removeColumn('price_quotes', 'min_acceptable_rate');
  await context.removeColumn('price_quotes', 'slippage_derived_at_ms');
};
