ALTER TABLE public.tb_scheduled_plan ADD template_id varchar(32) NULL;
COMMENT ON COLUMN public.tb_scheduled_plan.template_id IS '关联模板id';


ALTER TABLE public.tb_inspection_template ALTER COLUMN vehicle_type DROP NOT NULL;

ALTER TABLE public.tb_inspection_task_vehicle ADD is_normal varchar(2) NULL;
COMMENT ON COLUMN public.tb_inspection_task_vehicle.is_normal IS '是否正常';

ALTER TABLE public.tb_inspection_task_vehicle ADD abnormal_msg varchar(512) NULL;
COMMENT ON COLUMN public.tb_inspection_task_vehicle.abnormal_msg IS '异常信息';

ALTER TABLE public.tb_accident_info ALTER COLUMN driver DROP NOT NULL;
ALTER TABLE public.tb_accident_info ALTER COLUMN driver_license_number DROP NOT NULL;
ALTER TABLE public.tb_accident_info ALTER COLUMN driver_phone_number DROP NOT NULL;

--客户档案表联系人支持多选
ALTER TABLE public.tb_customer_archives ALTER COLUMN contact TYPE varchar(500) USING contact::varchar;
ALTER TABLE public.tb_customer_archives ALTER COLUMN phone TYPE varchar(1000) USING phone::varchar;

UPDATE tb_customer_archives
SET contact  = (
    SELECT TO_JSONB(JSONB_BUILD_ARRAY(contact))::TEXT
    FROM tb_customer_archives AS t
    WHERE tb_customer_archives.id = t.id
      and t.contact is not null
);

UPDATE tb_customer_archives
SET phone  = (
    SELECT TO_JSONB(JSONB_BUILD_ARRAY(phone))::TEXT
    FROM tb_customer_archives AS t
    WHERE tb_customer_archives.id = t.id
      and t.phone is not null
);
--