oidc-gateway-demo/database.md

77 lines
4.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 数据库表结构设计
## 一、统一认证网关(主工程)表结构
### 1. 用户表users
| 字段名 | 类型 | 说明 |
| -------------- | -------------- | -------------------------- |
| id | BIGINT | 主键,自增 |
| username | VARCHAR(50) | 用户名(租户/子系统内唯一)|
| password | VARCHAR(255) | 密码(加密存储) |
| user_type | ENUM | 用户类型TENANT/SUBSYSTEM|
| tenant_id | BIGINT | 所属租户ID外键->tenants.id所有用户必填标识归属租户 |
| email | VARCHAR(100) | 邮箱 |
| phone | VARCHAR(20) | 手机号 |
| real_name | VARCHAR(50) | 真实姓名 |
| status | ENUM | 状态ACTIVE/INACTIVE/LOCKED/DELETED|
| create_time | TIMESTAMP | 创建时间 |
| update_time | TIMESTAMP | 更新时间 |
| UNIQUE KEY uk_tenant_username (tenant_id, username) |
| UNIQUE KEY uk_subsystem_username (subsystem_id, username) |
> 主键id
> 外键tenant_id 关联 tenants.id所有用户必填subsystem_id 关联 subsystems.id仅子系统用户必填
### 2. 租户表tenants
| 字段名 | 类型 | 说明 |
| -------------- | -------------- | -------------------------- |
| id | BIGINT | 主键,自增 |
| tenant_code | VARCHAR(50) | 租户唯一标识 |
| tenant_name | VARCHAR(100) | 租户名称 |
| description | TEXT | 描述 |
| status | ENUM | 状态ACTIVE/INACTIVE |
| create_time | TIMESTAMP | 创建时间 |
| update_time | TIMESTAMP | 更新时间 |
> 主键id
### 3. 子系统表subsystems
| 字段名 | 类型 | 说明 |
| -------------- | -------------- | -------------------------- |
| id | BIGINT | 主键,自增 |
| client_id | VARCHAR(50) | 子系统唯一标识 |
| client_security | VARCHAR(50) | 子系统密钥 |
| description | TEXT | 描述 |
| callback_url | VARCHAR(255) | 子系统入回调地址 |
| status | ENUM | 状态ACTIVE/INACTIVE |
| create_time | TIMESTAMP | 创建时间 |
| update_time | TIMESTAMP | 更新时间 |
> 主键id
### 4. 租户-子系统权限表tenant_subsystem标识该租户可以登录哪些子系统
| 字段名 | 类型 | 说明 |
| -------------- | -------------- | -------------------------- |
| id | BIGINT | 主键,自增 |
| tenant_id | BIGINT | 租户ID外键->tenants.id |
| subsystem_id | BIGINT | 子系统ID外键->subsystems.id |
| status | ENUM | 状态ACTIVE/INACTIVE |
| create_time | TIMESTAMP | 创建时间 |
| update_time | TIMESTAMP | 更新时间 |
| UNIQUE KEY uk_tenant_subsystem (tenant_id, subsystem_id) |
### 5. 用户-子系统权限表user_subsystem标识该用户可以登录哪些子系统
| 字段名 | 类型 | 说明 |
| -------------- | -------------- | -------------------------- |
| id | BIGINT | 主键,自增 |
| user_id | BIGINT | 用户ID外键->users.id |
| subsystem_id | BIGINT | 子系统ID外键->subsystems.id |
| status | ENUM | 状态ACTIVE/INACTIVE |
| create_time | TIMESTAMP | 创建时间 |
| update_time | TIMESTAMP | 更新时间 |
| UNIQUE KEY uk_user_subsystem (user_id, subsystem_id) |
> 主键id
> 外键tenant_id 关联 tenants.idsubsystem_id 关联 subsystems.id