-- 统计表
-- ----------------------------
CREATE TABLE "t_stats_data" (
    "id" int4 NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "type" varchar(64) ,
    "collection_user_id" int4,
    "collection_type_id" int4,
    "collection_num" numeric(18,2),
    "name" text,
    "remark" text ,
    "status" int4 default 0,
    "create_time" timestamp(6),
    "update_time" timestamp(6),
    "prop1" text ,
    "prop2" text ,
    "version" int4 default 0,
    primary key ("id")
)
;
COMMENT ON COLUMN "t_stats_data"."collection_user_id" IS '统计用户id';
COMMENT ON COLUMN "t_stats_data"."collection_type_id" IS '统计类型id';
COMMENT ON COLUMN "t_stats_data"."collection_num" IS '统计总数';
COMMENT ON COLUMN "t_stats_data"."remark" IS '备注';
COMMENT ON COLUMN "t_stats_data"."type" IS '类型,商家';
COMMENT ON TABLE "t_stats_data" IS '统计表';

CREATE INDEX "t_stats_data_type_id" ON "t_stats_data" USING btree (
    type,collection_user_id,collection_type_id
    );

-- ----------------------------
-- Table structure for t_stats_record
--统计记录子表
-- ----------------------------
CREATE TABLE "t_stats_record" (
    "id" int4 NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "type" varchar(64) ,
    "collection_user_id" int4,
    "collection_type_id" int4,
    "ref_user_id" int4,
    "status" int4 default 0,
    "num" numeric(18,2) default 1,
    "extra_prop" text,
    "remark" text,
    "create_time" timestamp(6),
    "prop1" text ,
    "version" int4 default 0,
     primary key ("id")
);

COMMENT ON COLUMN "t_stats_record"."type" IS '类型';
COMMENT ON COLUMN "t_stats_record"."collection_user_id" IS '汇总用户id';
COMMENT ON COLUMN "t_stats_record"."collection_type_id" IS '统计数据来源id';
COMMENT ON COLUMN "t_stats_record"."ref_user_id" IS '记录来源用户id';
COMMENT ON COLUMN "t_stats_record"."num" IS '数量';
COMMENT ON COLUMN "t_stats_record"."extra_prop" IS '额外参数';
COMMENT ON COLUMN "t_stats_record"."remark" IS '备注';
COMMENT ON TABLE "t_stats_record" IS '统计表明细';

CREATE INDEX "t_stats_record_type_id" ON "t_stats_record" USING btree (
     type,collection_user_id,collection_type_id
    );