Files
2026-03-08 22:17:01 +08:00

154 lines
5.1 KiB
SQL

create table "user"
(
id bigint not null
primary key,
nickname varchar(255) not null,
avatar varchar(255) not null,
status smallint default 0 not null,
last_login_time timestamp with time zone,
create_time timestamp with time zone default now(),
update_time timestamp with time zone default now()
);
create table user_oauth
(
id bigint not null
primary key,
user_id bigint not null,
type smallint default 0 not null,
openid varchar(255) not null,
create_time timestamp with time zone default now(),
update_time timestamp with time zone default now()
);
create table space
(
id bigint primary key,
-- 核心业务字段
name varchar(255) not null,
invite_code varchar(30) not null unique,
owner_id bigint not null,
-- 状态字段
status smallint default 0 not null, -- 0 active 1 disabled 2 dissolved
disabled_time timestamp with time zone,
dissolve_time timestamp with time zone,
-- 时间字段
create_time timestamp with time zone default now() not null,
update_time timestamp with time zone default now() not null
);
create table space_member
(
id bigint primary key,
-- 关系核心字段
space_id bigint not null,
user_id bigint not null,
-- 角色 & 默认
role smallint default 2 not null,
is_default smallint default 0 not null,
sort_number integer default 0 not null,
member_name varchar(255) not null,
-- 成员状态
status smallint default 0 not null, -- 0 active 1 disabled 2 exited
disabled_time timestamp with time zone,
exit_time timestamp with time zone,
-- 时间字段
join_time timestamp with time zone default now() not null,
update_time timestamp with time zone default now() not null,
unique (space_id, user_id)
);
--记账分类默认表
create table finance_category_default
(
id bigint not null
primary key,
name varchar(64) not null,
icon varchar(64) not null,
type smallint default 0 not null,
sort_number integer default 0 not null,
create_time timestamp with time zone default now(),
update_time timestamp with time zone default now()
);
--记账分类空间表
create table finance_category_space
(
id bigint not null
primary key,
space_id bigint not null,
name varchar(64) not null,
icon varchar(64) not null,
type smallint default 0 not null,
sort_number integer default 0 not null,
create_by bigint not null,
create_time timestamp with time zone default now(),
update_by bigint not null,
update_time timestamp with time zone default now()
);
-- 记账记录表
create table finance_record
(
id bigint not null
primary key,
category_id bigint not null,
space_id bigint not null,
amount numeric(12, 2) not null,
remark varchar(255),
record_time date,
create_by bigint not null,
create_time timestamp with time zone default now(),
update_by bigint not null,
update_time timestamp with time zone default now()
);
-- session
CREATE TABLE session (
id bigint not null primary key,
space_id bigint not null,
type smallint not null,
name varchar(255),
avatar varchar(255),
description text,
status smallint default 0,
create_time timestamp with time zone default now(),
update_time timestamp with time zone default now()
)
-- session_member
create table session_member
(
id bigint not null
primary key,
session_id bigint not null,
user_id bigint not null,
remark varchar(255),
is_top smallint default 0 not null,
unread_count integer default 0,
last_msg_id bigint,
status integer default 0,
create_time timestamp with time zone default now(),
update_time timestamp with time zone default now()
);
create table session_message
(
id bigint not null
primary key,
session_id bigint not null,
sender_id bigint not null,
content text not null,
content_type smallint default 0 not null,
create_time timestamp with time zone default now()
);