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

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

export const up: Migration = async ({ context }) => {
  await safeApplyColumnChanges(context, {
    subscriptions: [
      {
        name: 'trial_start',
        field: {
          type: DataTypes.INTEGER,
          allowNull: true,
        },
      },
      {
        name: 'trial_end',
        field: {
          type: DataTypes.INTEGER,
          allowNull: true,
        },
      },
      {
        name: 'trial_settings',
        field: {
          type: DataTypes.JSON,
          allowNull: true,
        },
      },
    ],
  });
};

export const down: Migration = async ({ context }) => {
  await context.removeColumn('subscriptions', 'trail_start');
  await context.removeColumn('subscriptions', 'trail_end');
  await context.removeColumn('subscriptions', 'trail_settings');
};
