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

export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
  await db.execute(sql`
   ALTER TABLE "announcement" ALTER COLUMN "date" SET DEFAULT '2026-06-07T12:41:03.305Z';
  ALTER TABLE "calendar" ALTER COLUMN "date" SET DEFAULT '2026-06-07T12:41:03.609Z';
  ALTER TABLE "classifieds" ALTER COLUMN "until" SET DEFAULT '2026-07-05T12:41:03.673Z';
  ALTER TABLE "blog_blocks_gallery_items" ADD COLUMN "caption" varchar;
  ALTER TABLE "_blog_v_blocks_gallery_items" ADD COLUMN "caption" varchar;
  ALTER TABLE "group_blocks_gallery_items" ADD COLUMN "caption" varchar;
  ALTER TABLE "_group_v_blocks_gallery_items" ADD COLUMN "caption" varchar;
  ALTER TABLE "pages_blocks_gallery_items" ADD COLUMN "caption" varchar;
  ALTER TABLE "_pages_v_blocks_gallery_items" ADD COLUMN "caption" varchar;`)
}

export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
  await db.execute(sql`
   ALTER TABLE "announcement" ALTER COLUMN "date" SET DEFAULT '2026-06-07T11:31:06.259Z';
  ALTER TABLE "calendar" ALTER COLUMN "date" SET DEFAULT '2026-06-07T11:31:06.641Z';
  ALTER TABLE "classifieds" ALTER COLUMN "until" SET DEFAULT '2026-07-05T11:31:06.720Z';
  ALTER TABLE "blog_blocks_gallery_items" DROP COLUMN "caption";
  ALTER TABLE "_blog_v_blocks_gallery_items" DROP COLUMN "caption";
  ALTER TABLE "group_blocks_gallery_items" DROP COLUMN "caption";
  ALTER TABLE "_group_v_blocks_gallery_items" DROP COLUMN "caption";
  ALTER TABLE "pages_blocks_gallery_items" DROP COLUMN "caption";
  ALTER TABLE "_pages_v_blocks_gallery_items" DROP COLUMN "caption";`)
}
