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

export const up: Migration = async ({ context }) => {
  await context.createTable('revenue_snapshots', models.RevenueSnapshot.GENESIS_ATTRIBUTES);
  await createIndexIfNotExists(
    context,
    'revenue_snapshots',
    ['timestamp', 'currency_id', 'livemode', 'period_type'],
    'idx_revenue_snapshots_unique',
    { unique: true }
  );
};

export const down: Migration = async ({ context }) => {
  await context.removeIndex('revenue_snapshots', 'idx_revenue_snapshots_unique');
  await context.dropTable('revenue_snapshots');
};
