-- 户外招聘会绑定场地字段
-- 瀚高数据库 / PostgreSQL 兼容
-- 可重复执行。

ALTER TABLE "cms_outdoor_fair"
    ADD COLUMN IF NOT EXISTS "venue_id" BIGINT;

ALTER TABLE "cms_outdoor_fair"
    ADD COLUMN IF NOT EXISTS "venue_name" VARCHAR(200);

COMMENT ON COLUMN "cms_outdoor_fair"."venue_id" IS '绑定场地ID';
COMMENT ON COLUMN "cms_outdoor_fair"."venue_name" IS '绑定场地';

CREATE INDEX IF NOT EXISTS "idx_cms_outdoor_fair_venue_id" ON "cms_outdoor_fair" ("venue_id");

UPDATE "cms_outdoor_fair" fair
SET "venue_name" = venue."venue_name",
    "booth_count" = COALESCE(venue."floor_count", 0)
FROM "cms_venue_info" venue
WHERE fair."venue_id" = venue."id";
