/* eslint-disable no-console */
import { createIndexIfNotExists, type Migration } from '../migrate';

export const up: Migration = async ({ context }) => {
  console.log('🚀 Adding checkout_sessions performance indexes...');

  await createIndexIfNotExists(
    context,
    'checkout_sessions',
    ['payment_intent_id'],
    'idx_checkout_sessions_payment_intent'
  );
  await createIndexIfNotExists(context, 'checkout_sessions', ['subscription_id'], 'idx_checkout_sessions_subscription');
  await createIndexIfNotExists(context, 'checkout_sessions', ['status'], 'idx_checkout_sessions_status');

  console.log('✅ checkout_sessions indexes created');
};

export const down: Migration = async ({ context }) => {
  await context.removeIndex('checkout_sessions', 'idx_checkout_sessions_payment_intent');
  await context.removeIndex('checkout_sessions', 'idx_checkout_sessions_subscription');
  await context.removeIndex('checkout_sessions', 'idx_checkout_sessions_status');
};
