ALTER TYPE "public"."announcement_status" ADD VALUE IF NOT EXISTS 'pending_review';
ALTER TYPE "public"."announcement_status" ADD VALUE IF NOT EXISTS 'approved';
ALTER TYPE "public"."announcement_status" ADD VALUE IF NOT EXISTS 'returned';
ALTER TYPE "public"."announcement_status" ADD VALUE IF NOT EXISTS 'rejected';

ALTER TYPE "public"."online_lesson_status" ADD VALUE IF NOT EXISTS 'pending_review';
ALTER TYPE "public"."online_lesson_status" ADD VALUE IF NOT EXISTS 'approved';
ALTER TYPE "public"."online_lesson_status" ADD VALUE IF NOT EXISTS 'returned';
ALTER TYPE "public"."online_lesson_status" ADD VALUE IF NOT EXISTS 'rejected';

ALTER TABLE "announcements"
  ADD COLUMN IF NOT EXISTS "submitted_at" timestamp with time zone,
  ADD COLUMN IF NOT EXISTS "submitted_by" text,
  ADD COLUMN IF NOT EXISTS "reviewed_at" timestamp with time zone,
  ADD COLUMN IF NOT EXISTS "reviewed_by" text,
  ADD COLUMN IF NOT EXISTS "approved_at" timestamp with time zone,
  ADD COLUMN IF NOT EXISTS "approved_by" text,
  ADD COLUMN IF NOT EXISTS "published_at" timestamp with time zone,
  ADD COLUMN IF NOT EXISTS "published_by" text,
  ADD COLUMN IF NOT EXISTS "review_comment" text;

ALTER TABLE "online_lessons"
  ADD COLUMN IF NOT EXISTS "submitted_at" timestamp with time zone,
  ADD COLUMN IF NOT EXISTS "submitted_by" text,
  ADD COLUMN IF NOT EXISTS "reviewed_at" timestamp with time zone,
  ADD COLUMN IF NOT EXISTS "reviewed_by" text,
  ADD COLUMN IF NOT EXISTS "approved_at" timestamp with time zone,
  ADD COLUMN IF NOT EXISTS "approved_by" text,
  ADD COLUMN IF NOT EXISTS "published_by" text,
  ADD COLUMN IF NOT EXISTS "review_comment" text;

DO $$
BEGIN
  ALTER TABLE "announcements"
    ADD CONSTRAINT "announcements_submitted_by_users_id_fk"
    FOREIGN KEY ("submitted_by") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
  WHEN duplicate_object THEN NULL;
END $$;

DO $$
BEGIN
  ALTER TABLE "announcements"
    ADD CONSTRAINT "announcements_reviewed_by_users_id_fk"
    FOREIGN KEY ("reviewed_by") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
  WHEN duplicate_object THEN NULL;
END $$;

DO $$
BEGIN
  ALTER TABLE "announcements"
    ADD CONSTRAINT "announcements_approved_by_users_id_fk"
    FOREIGN KEY ("approved_by") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
  WHEN duplicate_object THEN NULL;
END $$;

DO $$
BEGIN
  ALTER TABLE "announcements"
    ADD CONSTRAINT "announcements_published_by_users_id_fk"
    FOREIGN KEY ("published_by") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
  WHEN duplicate_object THEN NULL;
END $$;

DO $$
BEGIN
  ALTER TABLE "online_lessons"
    ADD CONSTRAINT "online_lessons_submitted_by_users_id_fk"
    FOREIGN KEY ("submitted_by") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
  WHEN duplicate_object THEN NULL;
END $$;

DO $$
BEGIN
  ALTER TABLE "online_lessons"
    ADD CONSTRAINT "online_lessons_reviewed_by_users_id_fk"
    FOREIGN KEY ("reviewed_by") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
  WHEN duplicate_object THEN NULL;
END $$;

DO $$
BEGIN
  ALTER TABLE "online_lessons"
    ADD CONSTRAINT "online_lessons_approved_by_users_id_fk"
    FOREIGN KEY ("approved_by") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
  WHEN duplicate_object THEN NULL;
END $$;

DO $$
BEGIN
  ALTER TABLE "online_lessons"
    ADD CONSTRAINT "online_lessons_published_by_users_id_fk"
    FOREIGN KEY ("published_by") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;
EXCEPTION
  WHEN duplicate_object THEN NULL;
END $$;
