ALTER TABLE "organizations"
ADD COLUMN IF NOT EXISTS "is_active" boolean DEFAULT true NOT NULL;
--> statement-breakpoint
ALTER TABLE "organizations"
ADD COLUMN IF NOT EXISTS "deleted_at" timestamp with time zone;
--> statement-breakpoint
ALTER TABLE "organizations"
ADD COLUMN IF NOT EXISTS "deleted_by" text;
--> statement-breakpoint
DO $$
BEGIN
  IF NOT EXISTS (
    SELECT 1
    FROM pg_constraint
    WHERE conname = 'organizations_deleted_by_users_id_fk'
  ) THEN
    ALTER TABLE "organizations"
    ADD CONSTRAINT "organizations_deleted_by_users_id_fk"
    FOREIGN KEY ("deleted_by")
    REFERENCES "public"."users"("id")
    ON DELETE set null
    ON UPDATE no action;
  END IF;
END $$;
