ALTER TABLE "app_base_user"
    ADD COLUMN "version" int4 default 0,
    ADD COLUMN "daily_limit" int4 default 0,
    ADD COLUMN "weekly_limit" int4 default 0,
    ADD COLUMN "monthly_limit" int4 default 0;

COMMENT ON COLUMN "app_base_user"."daily_limit" IS '每日限额提醒';
COMMENT ON COLUMN "app_base_user"."weekly_limit" IS '每周限额提醒';
COMMENT ON COLUMN "app_base_user"."monthly_limit" IS '每月限额';



CREATE TABLE "questionnaire" (
    "id" int4 NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "type" varchar(64) default 'app',
    "title" varchar(512) NOT NULL,
    "description" text NOT NULL,
    "status" int2 default 0,
    "incr_amount" int4 default 1,
    "create_time" timestamp,
    PRIMARY KEY ("id")
);

COMMENT ON COLUMN "questionnaire"."incr_amount" IS '本次问卷提示额度,单位:万';


CREATE TABLE "question" (
    "id" int4 NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "type" varchar(64) default 'text',
    "questionnaire_id" int4 NOT NULL,
    "question_text" text NOT NULL,
    "question_choice_text" text,
    "status" int2 default 0,
    "create_time" timestamp,
    PRIMARY KEY ("id")
);

COMMENT ON COLUMN "question"."type" IS '问题类型;选择题单选:choice_single,选择题多选:choice_multi,文字:text';
COMMENT ON COLUMN "question"."question_choice_text" IS '选择题可选内容,json格式';

CREATE TABLE "question_answer" (
    "id" int4 NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "questionnaire_id" int4 NOT NULL,
    "question_id" int4 NOT NULL,
    "user_id" int4 NOT NULL,
    "answer_text" text NOT NULL,
    "create_time" timestamp,
    PRIMARY KEY ("id")
);


CREATE TABLE "user_limit_record" (
    "id" int4 NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "type" varchar(64) default 'questionnaire',
    "user_id" int4 NOT NULL,
    "previous_monthly_limit" int4 NOT NULL,
    "new_monthly_limit" int4 NOT NULL,
    "status" int2 default 0,
    "create_time" timestamp,
    "created_by" varchar(512) NOT NULL,
    PRIMARY KEY ("id")
);

COMMENT ON COLUMN "user_limit_record"."type" IS '提额类型;问卷:questionnaire,人工:customer';