数据库结构定义:添加组织及相关关系表
This commit is contained in:
parent
5ce122af28
commit
15df0ca22c
@ -14,6 +14,9 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
- uses: https://gitea.joylink.club/actions/rust-cache@v2
|
- uses: https://gitea.joylink.club/actions/rust-cache@v2
|
||||||
|
with:
|
||||||
|
cache-on-failure: true
|
||||||
|
cache-all-crates: true
|
||||||
- name: Install musl-tools
|
- name: Install musl-tools
|
||||||
run: apt-get update && apt-get install -y musl-tools
|
run: apt-get update && apt-get install -y musl-tools
|
||||||
- name: build Release
|
- name: build Release
|
||||||
|
@ -9,10 +9,11 @@ CREATE TABLE
|
|||||||
rtsa.user (
|
rtsa.user (
|
||||||
id SERIAL PRIMARY KEY, -- id 自增主键
|
id SERIAL PRIMARY KEY, -- id 自增主键
|
||||||
username VARCHAR(128) NOT NULL, -- 用户名
|
username VARCHAR(128) NOT NULL, -- 用户名
|
||||||
password VARCHAR(128) NOT NULL, -- 密码
|
password VARCHAR(256) NOT NULL, -- 密码
|
||||||
email VARCHAR(128) NULL, -- 邮箱
|
email VARCHAR(128) NULL UNIQUE, -- 邮箱
|
||||||
mobile VARCHAR(16) NULL, -- 手机号
|
mobile VARCHAR(16) NULL UNIQUE, -- 手机号
|
||||||
roles JSONB NOT NULL DEFAULT '[]', -- 角色列表
|
roles JSONB NOT NULL DEFAULT '[]', -- 角色列表
|
||||||
|
info JSONB NOT NULL DEFAULT '{}', -- 用户信息
|
||||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
|
||||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP -- 更新时间
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP -- 更新时间
|
||||||
);
|
);
|
||||||
@ -45,10 +46,224 @@ COMMENT ON COLUMN rtsa.user.mobile IS '手机号';
|
|||||||
|
|
||||||
COMMENT ON COLUMN rtsa.user.roles IS '角色列表';
|
COMMENT ON COLUMN rtsa.user.roles IS '角色列表';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.user.info IS '用户信息';
|
||||||
|
|
||||||
COMMENT ON COLUMN rtsa.user.created_at IS '创建时间';
|
COMMENT ON COLUMN rtsa.user.created_at IS '创建时间';
|
||||||
|
|
||||||
COMMENT ON COLUMN rtsa.user.updated_at IS '更新时间';
|
COMMENT ON COLUMN rtsa.user.updated_at IS '更新时间';
|
||||||
|
|
||||||
|
-- 创建组织表
|
||||||
|
CREATE TABLE
|
||||||
|
rtsa.organization (
|
||||||
|
id SERIAL PRIMARY KEY, -- id 自增主键
|
||||||
|
code VARCHAR(128) NOT NULL UNIQUE, -- 组织编码
|
||||||
|
name VARCHAR(128) NOT NULL, -- 组织名称
|
||||||
|
config JSONB NOT NULL DEFAULT '{}', -- 配置数据
|
||||||
|
parent_id INT NULL, -- 父组织id
|
||||||
|
creator_id INT NOT NULL, -- 创建用户id
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
|
||||||
|
updater_id INT NOT NULL, -- 更新用户id
|
||||||
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
|
||||||
|
FOREIGN KEY (parent_id) REFERENCES rtsa.organization (id) ON DELETE CASCADE, -- 父组织外键
|
||||||
|
FOREIGN KEY (creator_id) REFERENCES rtsa.user (id) ON DELETE CASCADE, -- 创建用户外键
|
||||||
|
FOREIGN KEY (updater_id) REFERENCES rtsa.user (id) ON DELETE CASCADE -- 更新用户外键
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 创建组织编码索引
|
||||||
|
CREATE INDEX ON rtsa.organization (code);
|
||||||
|
|
||||||
|
-- 创建组织名称索引
|
||||||
|
CREATE INDEX ON rtsa.organization (name);
|
||||||
|
|
||||||
|
-- 创建组织父组织索引
|
||||||
|
CREATE INDEX ON rtsa.organization (parent_id);
|
||||||
|
|
||||||
|
-- 创建组织创建用户索引
|
||||||
|
CREATE INDEX ON rtsa.organization (creator_id);
|
||||||
|
|
||||||
|
-- 创建组织更新用户索引
|
||||||
|
CREATE INDEX ON rtsa.organization (updater_id);
|
||||||
|
|
||||||
|
-- 注释组织表
|
||||||
|
COMMENT ON TABLE rtsa.organization IS '组织表';
|
||||||
|
|
||||||
|
-- 注释组织表字段
|
||||||
|
COMMENT ON COLUMN rtsa.organization.id IS 'id 自增主键';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization.code IS '组织编码';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization.name IS '组织名称';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization.config IS '配置数据';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization.parent_id IS '父组织id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization.creator_id IS '创建用户id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization.created_at IS '创建时间';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization.updater_id IS '更新用户id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization.updated_at IS '更新时间';
|
||||||
|
|
||||||
|
-- 创建组织用户表
|
||||||
|
CREATE TABLE
|
||||||
|
rtsa.organization_user (
|
||||||
|
id SERIAL PRIMARY KEY, -- id 自增主键
|
||||||
|
organization_id INT NOT NULL, -- 组织id
|
||||||
|
user_id INT NOT NULL, -- 用户id
|
||||||
|
student_id VARCHAR(128) NULL, -- 学工号
|
||||||
|
roles JSONB NOT NULL DEFAULT '[]', -- 组织角色列表
|
||||||
|
creator_id INT NOT NULL, -- 创建用户id
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
|
||||||
|
updater_id INT NOT NULL, -- 更新用户id
|
||||||
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
|
||||||
|
FOREIGN KEY (organization_id) REFERENCES rtsa.organization (id) ON DELETE CASCADE, -- 组织外键
|
||||||
|
FOREIGN KEY (user_id) REFERENCES rtsa.user (id) ON DELETE CASCADE, -- 用户外键
|
||||||
|
FOREIGN KEY (creator_id) REFERENCES rtsa.user (id) ON DELETE CASCADE, -- 创建用户外键
|
||||||
|
FOREIGN KEY (updater_id) REFERENCES rtsa.user (id) ON DELETE CASCADE, -- 更新用户外键
|
||||||
|
UNIQUE(organization_id, user_id) -- 组织id和用户id唯一
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 创建组织用户组织索引
|
||||||
|
CREATE INDEX ON rtsa.organization_user (organization_id);
|
||||||
|
|
||||||
|
-- 创建组织用户用户索引
|
||||||
|
CREATE INDEX ON rtsa.organization_user (user_id);
|
||||||
|
|
||||||
|
-- 创建组织用户学工号索引
|
||||||
|
CREATE INDEX ON rtsa.organization_user (student_id);
|
||||||
|
|
||||||
|
-- 创建组织用户角色索引
|
||||||
|
CREATE INDEX ON rtsa.organization_user USING GIN (roles);
|
||||||
|
|
||||||
|
-- 创建组织用户创建用户索引
|
||||||
|
CREATE INDEX ON rtsa.organization_user (creator_id);
|
||||||
|
|
||||||
|
-- 创建组织用户更新用户索引
|
||||||
|
CREATE INDEX ON rtsa.organization_user (updater_id);
|
||||||
|
|
||||||
|
-- 注释组织用户表
|
||||||
|
COMMENT ON TABLE rtsa.organization_user IS '组织用户表';
|
||||||
|
|
||||||
|
-- 注释组织用户表字段
|
||||||
|
COMMENT ON COLUMN rtsa.organization_user.id IS 'id 自增主键';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization_user.organization_id IS '组织id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization_user.user_id IS '用户id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization_user.student_id IS '学工号';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization_user.roles IS '组织角色列表';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization_user.creator_id IS '创建用户id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization_user.created_at IS '创建时间';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization_user.updater_id IS '更新用户id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization_user.updated_at IS '更新时间';
|
||||||
|
|
||||||
|
-- 创建feature表
|
||||||
|
CREATE TABLE
|
||||||
|
rtsa.feature (
|
||||||
|
id SERIAL PRIMARY KEY, -- id 自增主键
|
||||||
|
feature_type INT NOT NULL, -- feature类型
|
||||||
|
name VARCHAR(128) NOT NULL, -- feature名称
|
||||||
|
description TEXT NOT NULL, -- feature描述
|
||||||
|
config JSONB NOT NULL, -- feature配置
|
||||||
|
is_published BOOLEAN NOT NULL DEFAULT TRUE, -- 是否上架
|
||||||
|
creator_id INT NOT NULL, -- 创建用户id
|
||||||
|
updater_id INT NOT NULL, -- 更新用户id
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
|
||||||
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
|
||||||
|
FOREIGN KEY (creator_id) REFERENCES rtsa.user (id) ON DELETE CASCADE, -- 用户外键
|
||||||
|
FOREIGN KEY (updater_id) REFERENCES rtsa.user (id) ON DELETE CASCADE, -- 用户外键
|
||||||
|
UNIQUE(feature_type, name) -- feature类型和名称唯一
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 创建feature类型索引
|
||||||
|
CREATE INDEX ON rtsa.feature (feature_type);
|
||||||
|
|
||||||
|
-- 创建feature名称索引
|
||||||
|
CREATE INDEX ON rtsa.feature (name);
|
||||||
|
|
||||||
|
-- 注释仿真feature表
|
||||||
|
COMMENT ON TABLE rtsa.feature IS 'feature表';
|
||||||
|
|
||||||
|
-- 注释仿真feature表字段
|
||||||
|
COMMENT ON COLUMN rtsa.feature.id IS 'id 自增主键';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.feature.feature_type IS 'feature类型';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.feature.name IS 'feature名称';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.feature.description IS 'feature描述';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.feature.config IS 'feature配置';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.feature.is_published IS '是否上架';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.feature.creator_id IS '创建用户id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.feature.created_at IS '创建时间';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.feature.updated_at IS '更新时间';
|
||||||
|
|
||||||
|
-- 创建组织功能表
|
||||||
|
CREATE TABLE
|
||||||
|
rtsa.organization_feature (
|
||||||
|
id SERIAL PRIMARY KEY, -- id 自增主键
|
||||||
|
organization_id INT NOT NULL, -- 组织id
|
||||||
|
feature_id INT NOT NULL, -- feature id
|
||||||
|
config JSONB NOT NULL, -- 组织功能配置
|
||||||
|
creator_id INT NOT NULL, -- 创建用户id
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
|
||||||
|
updater_id INT NOT NULL, -- 更新用户id
|
||||||
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
|
||||||
|
FOREIGN KEY (organization_id) REFERENCES rtsa.organization (id) ON DELETE CASCADE, -- 组织外键
|
||||||
|
FOREIGN KEY (feature_id) REFERENCES rtsa.feature (id) ON DELETE CASCADE, -- feature外键
|
||||||
|
FOREIGN KEY (creator_id) REFERENCES rtsa.user (id) ON DELETE CASCADE, -- 创建用户外键
|
||||||
|
FOREIGN KEY (updater_id) REFERENCES rtsa.user (id) ON DELETE CASCADE, -- 更新用户外键
|
||||||
|
UNIQUE(organization_id, feature_id) -- 组织id和feature id唯一
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 创建组织功能组织索引
|
||||||
|
CREATE INDEX ON rtsa.organization_feature (organization_id);
|
||||||
|
|
||||||
|
-- 创建组织功能feature索引
|
||||||
|
CREATE INDEX ON rtsa.organization_feature (feature_id);
|
||||||
|
|
||||||
|
-- 创建组织功能配置项索引
|
||||||
|
CREATE INDEX ON rtsa.organization_feature USING GIN (config);
|
||||||
|
|
||||||
|
-- 创建组织功能创建用户索引
|
||||||
|
CREATE INDEX ON rtsa.organization_feature (creator_id);
|
||||||
|
|
||||||
|
-- 创建组织功能更新用户索引
|
||||||
|
CREATE INDEX ON rtsa.organization_feature (updater_id);
|
||||||
|
|
||||||
|
-- 注释组织功能表
|
||||||
|
COMMENT ON TABLE rtsa.organization_feature IS '组织功能表';
|
||||||
|
|
||||||
|
-- 注释组织功能表字段
|
||||||
|
COMMENT ON COLUMN rtsa.organization_feature.id IS 'id 自增主键';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization_feature.organization_id IS '组织id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization_feature.feature_id IS 'feature id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization_feature.config IS '组织功能配置';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization_feature.creator_id IS '创建用户id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization_feature.created_at IS '创建时间';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization_feature.updater_id IS '更新用户id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.organization_feature.updated_at IS '更新时间';
|
||||||
|
|
||||||
-- 创建草稿数据表
|
-- 创建草稿数据表
|
||||||
CREATE TABLE
|
CREATE TABLE
|
||||||
rtsa.draft_data (
|
rtsa.draft_data (
|
||||||
@ -194,81 +409,181 @@ COMMENT ON COLUMN rtsa.release_data_version.user_id IS '发布用户id';
|
|||||||
|
|
||||||
COMMENT ON COLUMN rtsa.release_data_version.created_at IS '创建时间';
|
COMMENT ON COLUMN rtsa.release_data_version.created_at IS '创建时间';
|
||||||
|
|
||||||
-- 创建feature表
|
-- 创建发布数据集表
|
||||||
CREATE TABLE
|
CREATE TABLE
|
||||||
rtsa.feature (
|
rtsa.release_data_set (
|
||||||
id SERIAL PRIMARY KEY, -- id 自增主键
|
id SERIAL PRIMARY KEY, -- id 自增主键
|
||||||
feature_type INT NOT NULL, -- feature类型
|
data_set_type INT NOT NULL, -- 数据集类型
|
||||||
name VARCHAR(128) NOT NULL UNIQUE, -- feature名称
|
name VARCHAR(128) NOT NULL, -- 发布数据集名称
|
||||||
description TEXT NOT NULL, -- feature描述
|
description TEXT NOT NULL, -- 发布数据集描述
|
||||||
config JSONB NOT NULL, -- feature配置
|
config JSONB NULL, -- 数据集相关配置项
|
||||||
is_published BOOLEAN NOT NULL DEFAULT TRUE, -- 是否上架
|
is_published BOOLEAN NOT NULL DEFAULT TRUE, -- 是否上架
|
||||||
creator_id INT NOT NULL, -- 创建用户id
|
creator_id INT NOT NULL, -- 创建用户id
|
||||||
updater_id INT NOT NULL, -- 更新用户id
|
|
||||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
|
||||||
|
updater_id INT NOT NULL, -- 更新用户id
|
||||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
|
||||||
FOREIGN KEY (creator_id) REFERENCES rtsa.user (id) ON DELETE CASCADE, -- 用户外键
|
FOREIGN KEY (creator_id) REFERENCES rtsa.user (id) ON DELETE CASCADE, -- 创建用户外键
|
||||||
FOREIGN KEY (updater_id) REFERENCES rtsa.user (id) ON DELETE CASCADE -- 用户外键
|
FOREIGN KEY (updater_id) REFERENCES rtsa.user (id) ON DELETE CASCADE, -- 更新用户外键
|
||||||
|
UNIQUE(data_set_type, name) -- 数据集类型+name唯一
|
||||||
);
|
);
|
||||||
|
|
||||||
-- 创建feature类型索引
|
-- 创建发布数据集类型索引
|
||||||
CREATE INDEX ON rtsa.feature (feature_type);
|
CREATE INDEX ON rtsa.release_data_set (data_set_type);
|
||||||
|
|
||||||
-- 创建feature名称索引
|
-- 创建发布数据集名称索引
|
||||||
CREATE INDEX ON rtsa.feature (name);
|
CREATE INDEX ON rtsa.release_data_set (name);
|
||||||
|
|
||||||
-- 注释仿真feature表
|
-- 创建发布数据集配置项索引
|
||||||
COMMENT ON TABLE rtsa.feature IS 'feature表';
|
CREATE INDEX ON rtsa.release_data_set USING GIN (config);
|
||||||
|
|
||||||
-- 注释仿真feature表字段
|
-- 创建发布数据集创建用户索引
|
||||||
COMMENT ON COLUMN rtsa.feature.id IS 'id 自增主键';
|
CREATE INDEX ON rtsa.release_data_set (creator_id);
|
||||||
|
|
||||||
COMMENT ON COLUMN rtsa.feature.feature_type IS 'feature类型';
|
-- 创建发布数据集更新用户索引
|
||||||
|
CREATE INDEX ON rtsa.release_data_set (updater_id);
|
||||||
|
|
||||||
COMMENT ON COLUMN rtsa.feature.name IS 'feature名称';
|
-- 创建发布数据集索引
|
||||||
|
CREATE INDEX ON rtsa.release_data_set (data_set_type, name);
|
||||||
|
|
||||||
COMMENT ON COLUMN rtsa.feature.description IS 'feature描述';
|
-- 注释发布数据集表
|
||||||
|
COMMENT ON TABLE rtsa.release_data_set IS '发布数据集表';
|
||||||
|
|
||||||
COMMENT ON COLUMN rtsa.feature.config IS 'feature配置';
|
-- 注释发布数据集表字段
|
||||||
|
COMMENT ON COLUMN rtsa.release_data_set.id IS 'id 自增主键';
|
||||||
|
|
||||||
COMMENT ON COLUMN rtsa.feature.is_published IS '是否上架';
|
COMMENT ON COLUMN rtsa.release_data_set.data_set_type IS '数据集类型';
|
||||||
|
|
||||||
COMMENT ON COLUMN rtsa.feature.creator_id IS '创建用户id';
|
COMMENT ON COLUMN rtsa.release_data_set.name IS '发布数据集名称';
|
||||||
|
|
||||||
COMMENT ON COLUMN rtsa.feature.created_at IS '创建时间';
|
COMMENT ON COLUMN rtsa.release_data_set.description IS '发布数据集描述';
|
||||||
|
|
||||||
COMMENT ON COLUMN rtsa.feature.updated_at IS '更新时间';
|
COMMENT ON COLUMN rtsa.release_data_set.config IS '数据集相关配置项';
|
||||||
|
|
||||||
-- 创建用户配置表
|
COMMENT ON COLUMN rtsa.release_data_set.is_published IS '是否上架';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.release_data_set.creator_id IS '创建用户id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.release_data_set.created_at IS '创建时间';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.release_data_set.updater_id IS '更新用户id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.release_data_set.updated_at IS '更新时间';
|
||||||
|
|
||||||
|
-- 创建发布数据集数据表
|
||||||
CREATE TABLE
|
CREATE TABLE
|
||||||
rtsa.user_config (
|
rtsa.release_data_set_data (
|
||||||
id SERIAL PRIMARY KEY, -- id 自增主键
|
id SERIAL PRIMARY KEY, -- id 自增主键
|
||||||
|
release_data_set_id INT NOT NULL, -- 发布数据集id
|
||||||
|
release_data_id INT NOT NULL, -- 发布数据id
|
||||||
|
order_index INT NOT NULL, -- 排序索引
|
||||||
|
FOREIGN KEY (release_data_set_id) REFERENCES rtsa.release_data_set (id) ON DELETE CASCADE, -- 发布数据集外键
|
||||||
|
FOREIGN KEY (release_data_id) REFERENCES rtsa.release_data (id) ON DELETE CASCADE, -- 发布数据外键
|
||||||
|
UNIQUE(release_data_set_id, release_data_id) -- 发布数据集id和发布数据id唯一
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 创建发布数据集数据发布数据集索引
|
||||||
|
CREATE INDEX ON rtsa.release_data_set_data (release_data_set_id);
|
||||||
|
|
||||||
|
-- 创建发布数据集数据发布数据索引
|
||||||
|
CREATE INDEX ON rtsa.release_data_set_data (release_data_id);
|
||||||
|
|
||||||
|
-- 注释发布数据集数据表
|
||||||
|
COMMENT ON TABLE rtsa.release_data_set_data IS '发布数据集数据表';
|
||||||
|
|
||||||
|
-- 注释发布数据集数据表字段
|
||||||
|
COMMENT ON COLUMN rtsa.release_data_set_data.id IS 'id 自增主键';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.release_data_set_data.release_data_set_id IS '发布数据集id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.release_data_set_data.release_data_id IS '发布数据id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.release_data_set_data.order_index IS '排序索引';
|
||||||
|
|
||||||
|
-- 创建用户数据表
|
||||||
|
CREATE TABLE
|
||||||
|
rtsa.user_data (
|
||||||
|
id SERIAL PRIMARY KEY, -- id 自增主键
|
||||||
|
organization_id INT NOT NULL, -- 组织id
|
||||||
user_id INT NOT NULL, -- 用户id
|
user_id INT NOT NULL, -- 用户id
|
||||||
config_type INT NOT NULL, -- 配置类型
|
data_type INT NOT NULL, -- 数据类型
|
||||||
config BYTEA NOT NULL, -- 配置
|
data JSONB NOT NULL, -- 数据
|
||||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
|
||||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间
|
||||||
|
FOREIGN KEY (organization_id) REFERENCES rtsa.organization (id) ON DELETE CASCADE, -- 组织外键
|
||||||
FOREIGN KEY (user_id) REFERENCES rtsa.user (id) ON DELETE CASCADE -- 用户外键
|
FOREIGN KEY (user_id) REFERENCES rtsa.user (id) ON DELETE CASCADE -- 用户外键
|
||||||
);
|
);
|
||||||
|
|
||||||
-- 创建用户配置用户索引
|
-- 创建用户数据组织索引
|
||||||
CREATE INDEX ON rtsa.user_config (user_id);
|
CREATE INDEX ON rtsa.user_data (organization_id);
|
||||||
|
|
||||||
-- 创建用户配置类型索引
|
-- 创建用户数据用户索引
|
||||||
CREATE INDEX ON rtsa.user_config (config_type);
|
CREATE INDEX ON rtsa.user_data (user_id);
|
||||||
|
|
||||||
-- 注释用户feature配置表
|
-- 创建用户数据类型索引
|
||||||
COMMENT ON TABLE rtsa.user_config IS '用户feature配置表';
|
CREATE INDEX ON rtsa.user_data (data_type);
|
||||||
|
|
||||||
-- 注释用户feature配置表字段
|
-- 创建用户数据配置项索引
|
||||||
COMMENT ON COLUMN rtsa.user_config.id IS 'id 自增主键';
|
CREATE INDEX ON rtsa.user_data USING GIN (data);
|
||||||
|
|
||||||
COMMENT ON COLUMN rtsa.user_config.user_id IS '用户id';
|
-- 创建用户数据索引
|
||||||
|
CREATE INDEX ON rtsa.user_data (organization_id, user_id, data_type);
|
||||||
|
|
||||||
COMMENT ON COLUMN rtsa.user_config.config_type IS '配置类型';
|
-- 注释用户数据表
|
||||||
|
COMMENT ON TABLE rtsa.user_data IS '用户数据表';
|
||||||
|
|
||||||
COMMENT ON COLUMN rtsa.user_config.config IS '配置';
|
-- 注释用户数据表字段
|
||||||
|
COMMENT ON COLUMN rtsa.user_data.id IS 'id 自增主键';
|
||||||
|
|
||||||
COMMENT ON COLUMN rtsa.user_config.created_at IS '创建时间';
|
COMMENT ON COLUMN rtsa.user_data.user_id IS '用户id';
|
||||||
|
|
||||||
COMMENT ON COLUMN rtsa.user_config.updated_at IS '更新时间';
|
COMMENT ON COLUMN rtsa.user_data.data_type IS '数据类型';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.user_data.data IS '数据';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.user_data.created_at IS '创建时间';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.user_data.updated_at IS '更新时间';
|
||||||
|
|
||||||
|
-- 创建用户操作日志表
|
||||||
|
CREATE TABLE
|
||||||
|
rtsa.user_operation_log (
|
||||||
|
id SERIAL PRIMARY KEY, -- id 自增主键
|
||||||
|
organization_id INT NOT NULL, -- 组织id
|
||||||
|
user_id INT NOT NULL, -- 用户id
|
||||||
|
log_type INT NOT NULL, -- 日志类型
|
||||||
|
log_data JSONB NOT NULL, -- 日志数据
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
|
||||||
|
FOREIGN KEY (organization_id) REFERENCES rtsa.organization (id) ON DELETE CASCADE, -- 组织外键
|
||||||
|
FOREIGN KEY (user_id) REFERENCES rtsa.user (id) ON DELETE CASCADE -- 用户外键
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 创建用户操作日志组织索引
|
||||||
|
CREATE INDEX ON rtsa.user_operation_log (organization_id);
|
||||||
|
|
||||||
|
-- 创建用户操作日志用户索引
|
||||||
|
CREATE INDEX ON rtsa.user_operation_log (user_id);
|
||||||
|
|
||||||
|
-- 创建用户操作日志类型索引
|
||||||
|
CREATE INDEX ON rtsa.user_operation_log (log_type);
|
||||||
|
|
||||||
|
-- 创建用户操作日志数据索引
|
||||||
|
CREATE INDEX ON rtsa.user_operation_log USING GIN (log_data);
|
||||||
|
|
||||||
|
-- 创建用户操作日志索引
|
||||||
|
CREATE INDEX ON rtsa.user_operation_log (organization_id, user_id, log_type, created_at);
|
||||||
|
|
||||||
|
-- 注释用户操作日志表
|
||||||
|
COMMENT ON TABLE rtsa.user_operation_log IS '用户操作日志表';
|
||||||
|
|
||||||
|
-- 注释用户操作日志表字段
|
||||||
|
COMMENT ON COLUMN rtsa.user_operation_log.id IS 'id 自增主键';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.user_operation_log.organization_id IS '组织id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.user_operation_log.user_id IS '用户id';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.user_operation_log.log_type IS '日志类型';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.user_operation_log.log_data IS '日志记录数据';
|
||||||
|
|
||||||
|
COMMENT ON COLUMN rtsa.user_operation_log.created_at IS '创建时间';
|
||||||
|
Loading…
Reference in New Issue
Block a user