import Sequelize from 'sequelize';

import type { Migration } from '../migrate';
import models from '../models';

// Remove uniq constraint from payment_currency.symbol
export const up: Migration = async ({ context }) => {
  const [rows] = await context.sequelize.query('SELECT * FROM payment_currencies');
  await context.sequelize.query('DROP TABLE IF EXISTS payment_currencies_tmp');
  await context.renameTable('payment_currencies', 'payment_currencies_tmp');
  await context.createTable('payment_currencies', models.PaymentCurrency.GENESIS_ATTRIBUTES);
  await context.bulkInsert(
    'payment_currencies',
    rows as any,
    {},
    {
      metadata: { type: new Sequelize.JSON() },
    }
  );
};

export const down: Migration = async () => {};
