import { DataTypes } from 'sequelize';

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

export const up: Migration = async ({ context }) => {
  await safeApplyColumnChanges(context, {
    customers: [
      {
        name: 'preference',
        field: {
          type: DataTypes.JSON,
          defaultValue: JSON.stringify({
            notification: {
              frequency: 'monthly',
              schedule: {
                time: '10:00',
                date: 1,
              },
            },
          }),
        },
      },
    ],
  });
};

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