drop table if exists b_todo_file; drop table if exists b_todo_rating; drop table if exists b_todo_log; drop table if exists b_todo; -- 待办 create table b_todo ( id bigint primary key, family_id bigint not null, name varchar(64) not null, description varchar(512) default '', status smallint not null default 0, priority smallint not null default 0, assignee_id bigint, deadline timestamptz, completed_at timestamptz, repeat_type smallint not null default 0, remind_at timestamptz, complete_note varchar(512) default '', sort_number int not null default 0, create_time timestamptz, update_time timestamptz, create_by bigint, update_by bigint ); -- 日志 create table b_todo_log ( id bigint primary key, family_id bigint not null, todo_id bigint not null, type smallint not null, content varchar(1024) default '', ref_id bigint, create_time timestamptz, update_time timestamptz, create_by bigint, update_by bigint ); -- 评分 create table b_todo_rating ( id bigint primary key, family_id bigint not null, todo_id bigint not null, rater_id bigint not null, rating smallint not null, content varchar(256) default '', create_time timestamptz, update_time timestamptz, create_by bigint, update_by bigint ); -- 附件(完成时上传的图片/视频等) create table b_todo_file ( id bigint primary key, family_id bigint not null, todo_log_id bigint not null, todo_id bigint not null, file_key varchar(256) not null, file_name varchar(256), file_type smallint default 1, mime_type varchar(64), file_size bigint, width int, height int, duration int, sort_order int not null default 0, create_time timestamptz, update_time timestamptz, create_by bigint, update_by bigint ); -- 索引 create index idx_b_todo_family_status on b_todo (family_id, status, sort_number, id); create index idx_b_todo_family_assignee on b_todo (family_id, assignee_id, status); create index idx_b_todo_log_todo on b_todo_log (family_id, todo_id, create_time, id); create unique index idx_b_todo_log_todo_type_ref on b_todo_log (family_id, todo_id, type, ref_id); create index idx_b_todo_rating_todo on b_todo_rating (family_id, todo_id, id); create unique index idx_b_todo_rating_todo_rater on b_todo_rating (family_id, todo_id, rater_id); create index idx_b_todo_file_todo_log on b_todo_file (family_id, todo_log_id, sort_order); create index idx_b_todo_file_todo on b_todo_file (family_id, todo_id, id);