数据库 Schema
连接信息
| 数据库 | 类型 | 端口 | 用户 | 密码 | 用途 |
|---|---|---|---|---|---|
| sayclaw_admin | MySQL 8.0 | 127.0.0.1:3306 | root | SayClaw_MySQL_2026! | 管理后台 |
| sayclaw_portal | MySQL 8.0 | 127.0.0.1:3306 | root | SayClaw_MySQL_2026! | 员工门户 |
| oneapi | MySQL 8.0 | 127.0.0.1:3306 | root | SayClaw_MySQL_2026! | One-API |
| postgres | PostgreSQL 15 | 127.0.0.1:5432 | postgres | SayClaw_PG_2026! | One API 旧数据 |
# 连接 MySQL
docker exec -it sayclaw-mysql mysql -uroot -p'SayClaw_MySQL_2026!' sayclaw_admin
# 连接 PostgreSQL
docker exec -it sayclaw-postgres psql -U postgres
sayclaw_admin 库(管理后台)
servers — 服务器注册
CREATE TABLE `servers` (
`id` varchar(36) NOT NULL DEFAULT (uuid()),
`name` varchar(100) DEFAULT NULL,
`ip` varchar(45) DEFAULT NULL,
`region` varchar(50) DEFAULT NULL,
`provider` varchar(50) DEFAULT 'gcp',
`cpu_cores` int DEFAULT NULL,
`memory_gb` int DEFAULT NULL,
`disk_gb` int DEFAULT NULL,
`status` varchar(20) NOT NULL DEFAULT 'active',
`ssh_user` varchar(50) DEFAULT 'root',
`ssh_port` int NOT NULL DEFAULT '22',
`docker_port` int NOT NULL DEFAULT '2376',
`notes` text,
`created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`deleted_at` datetime(3) DEFAULT NULL,
`ssh_key_path` varchar(200) NOT NULL DEFAULT '/root/.ssh/id_ed25519_openclaw',
PRIMARY KEY (`id`),
KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
oc_instances — OC 实例注册
CREATE TABLE `oc_instances` (
`id` varchar(100) NOT NULL,
`container_id` varchar(100) DEFAULT NULL,
`server_id` varchar(36) DEFAULT NULL,
`assigned_user_id` varchar(36) DEFAULT NULL,
`name` varchar(100) DEFAULT NULL,
`gateway_port` int DEFAULT NULL,
`gateway_url` varchar(255) DEFAULT NULL,
`gateway_token` varchar(255) DEFAULT NULL,
`model` varchar(100) DEFAULT NULL,
`health_status` varchar(20) NOT NULL DEFAULT 'unknown',
`health_fail_count` int NOT NULL DEFAULT '0',
`total_requests` bigint NOT NULL DEFAULT '0',
`total_tokens` bigint NOT NULL DEFAULT '0',
`last_health_at` datetime(3) DEFAULT NULL,
`created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`deleted_at` datetime(3) DEFAULT NULL,
`notes` text,
`config_json` text,
PRIMARY KEY (`id`),
KEY `idx_server` (`server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
重要约束
- 没有
status字段,用deleted_at IS NULL判断是否存活 - SQL LIKE 匹配用
'oc-ai-jp-2-%'(不用'oc-ai-jp-2-0%',会漏掉 10+)
admin_users — 管理员账号
CREATE TABLE `admin_users` (
`id` varchar(36) NOT NULL DEFAULT (uuid()),
`email` varchar(255) NOT NULL,
`password_hash` varchar(255) NOT NULL,
`name` varchar(100) DEFAULT NULL,
`role` varchar(20) NOT NULL DEFAULT 'admin',
`status` varchar(20) NOT NULL DEFAULT 'active',
`last_login_at` datetime(3) DEFAULT NULL,
`created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`deleted_at` datetime(3) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
instance_users — 实例分配(admin 侧)
CREATE TABLE `instance_users` (
`instance_id` varchar(100) NOT NULL,
`user_email` varchar(255) NOT NULL,
`assigned_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
PRIMARY KEY (`instance_id`,`user_email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
其他表
| 表名 | 说明 |
|---|---|
admin_logs | 管理操作审计日志 |
admin_tasks | 后台任务队列 (admin-api) |
ai_models | AI 模型注册 |
alert_rules | 告警规则 |
api_master_keys | API 主密钥 (AES-256-GCM 加密) |
containers | 容器注册 |
instance_active_assets | 实例活跃资产 |
instance_templates | 实例模板 |
job_runs | 定时任务执行记录 |
_deprecated_litellm_virtual_keys (已废弃) | One API 虚拟密钥 |
api_master_keys | LLM 主密钥 |
oneapi.logs | LLM 请求日志 |
_deprecated_llm_sub_keys (已废弃) | LLM 子密钥 |
marketplace_installs | 应用市场安装记录 |
marketplace_items | 应用市场条目 |
oc_api_keys | OC API 密钥 |
oc_chat_bindings | Bot 绑定(已废弃) |
oc_health_logs | 健康检查日志 |
profession_instances | 职业-实例关联 |
professions | 职业定义 |
server_metrics | 服务器指标 |
task_queue | 任务队列 |
usage_daily | 日用量统计 |
sayclaw_portal 库(员工门户)
users — 门户用户
CREATE TABLE `users` (
`id` varchar(36) NOT NULL DEFAULT (uuid()),
`email` varchar(255) NOT NULL,
`name` varchar(100) DEFAULT NULL,
`password_hash` varchar(64) DEFAULT NULL,
`google_id` varchar(128) DEFAULT NULL,
`department` varchar(100) DEFAULT NULL,
`status` varchar(20) NOT NULL DEFAULT 'active',
`quota_daily` bigint NOT NULL DEFAULT '100000',
`created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`revoked_at` datetime(3) DEFAULT NULL,
`telegram_user_id` bigint DEFAULT NULL,
`telegram_username` varchar(64) DEFAULT NULL,
`telegram_bound_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
user_instances — 用户-实例绑定
CREATE TABLE `user_instances` (
`user_id` varchar(36) NOT NULL,
`instance_id` varchar(100) NOT NULL,
`tg_user_id` bigint DEFAULT NULL,
`tg_username` varchar(64) DEFAULT NULL,
`tg_bound_at` datetime DEFAULT NULL,
`tg_bot_token` varchar(200) DEFAULT NULL,
`tg_bot_username` varchar(64) DEFAULT NULL,
`profession_id` varchar(64) DEFAULT NULL COMMENT '领取的职业 ID',
`setup_status` enum('pending','bootstrapping','ready','failed')
DEFAULT 'pending' COMMENT '初始化状态',
PRIMARY KEY (`user_id`,`instance_id`),
CONSTRAINT `user_instances_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
chat_messages — 聊天记录
CREATE TABLE `chat_messages` (
`id` bigint NOT NULL AUTO_INCREMENT,
`user_id` varchar(36) NOT NULL,
`instance_id` varchar(64) NOT NULL DEFAULT '',
`role` enum('user','assistant') NOT NULL,
`content` text NOT NULL,
`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
`tokens` int DEFAULT '0',
PRIMARY KEY (`id`),
KEY `idx_user_instance` (`user_id`,`instance_id`),
KEY `idx_created` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
其他表
| 表名 | 说明 |
|---|---|
instances | 实例视图(可能已废弃) |
tg_bind_codes | TG 绑定验证码(v3 已废弃) |
usage_daily | 日用量统计(待实现) |
关键约束
- 不用 float,金额用
DECIMAL(10,6) - 只做软删除(
deleted_at),不物理删除行 - 跨库查询用全名:
sayclaw_admin.oc_instances - 中文写 MySQL 必须加
--default-character-set=utf8mb4 oc_instances无status字段,用WHERE deleted_at IS NULL