import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres';

export async function up({ db }: MigrateUpArgs): Promise<void> {
  // redirect_permanent is a non-localized checkbox → stored on the main pages table
  await db.execute(sql`
    ALTER TABLE "pages" ADD COLUMN IF NOT EXISTS "redirect_permanent" boolean DEFAULT true;
  `);

  // redirect_url is a localized text field → stored on the pages_locales table
  await db.execute(sql`
    ALTER TABLE "pages_locales" ADD COLUMN IF NOT EXISTS "redirect_url" varchar;
  `);
}

export async function down({ db }: MigrateDownArgs): Promise<void> {
  await db.execute(sql`
    ALTER TABLE "pages" DROP COLUMN IF EXISTS "redirect_permanent";
  `);
  await db.execute(sql`
    ALTER TABLE "pages_locales" DROP COLUMN IF EXISTS "redirect_url";
  `);
}
