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

export const up: Migration = async ({ context }) => {
  await safeApplyColumnChanges(context, {
    settings: [
      {
        name: 'component_did',
        field: { type: DataTypes.STRING, allowNull: true },
      },
    ],
  });
  const columns = await context.describeTable('settings');
  if (columns.mountLocation) {
    await context.renameColumn('settings', 'mountLocation', 'mount_location');
  }
};

export const down: Migration = async ({ context }) => {
  await context.removeColumn('settings', 'component_did');
  await context.renameColumn('settings', 'mount_location', 'mountLocation');
};
