数据源
登记数据库连接、测试连通性、列出已有数据源。数据源是扫描与分级的入口。
数据源(datasource)代表一个待分类的数据库连接。建好之后,对它发起扫描即可逐字段定级。
创建数据源
text
POST /api/v1/datasources需 superadmin / admin / dba 角色。
请求体
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
name | string | 是 | 数据源显示名 |
db_type | string | 是 | 数据库类型,如 postgresql / mysql / oracle / dm(达梦) |
host | string | 否 | 主机地址 |
port | int | 否 | 端口 |
database | string | 否 | 库名 |
username | string | 否 | 连接用户名 |
password | string | 否 | 连接密码 |
ssl_enabled | bool | 否 | 是否启用 SSL |
import_mode | string | 否 | 接入方式 |
freshness_threshold_days | int | 否 | 数据新鲜度阈值(天) |
响应
| 字段 | 类型 | 说明 |
|---|---|---|
id | UUID | 数据源 ID |
name | string | 名称 |
db_type | string | 数据库类型 |
status | string | 连接状态 |
schema_count | int | 已发现 schema 数 |
table_count | int | 已发现表数 |
field_count | int | 已发现字段数 |
last_scan_at | datetime | null | 上次扫描时间 |
created_at | datetime | 创建时间 |
示例
bash
curl -X POST https://your-dcg-host/api/v1/datasources \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "生产用户库",
"db_type": "postgresql",
"host": "10.0.0.12",
"port": 5432,
"database": "userdb",
"username": "readonly",
"password": "••••••"
}'只读账号就够
扫描只做 schema 反射和少量采样,强烈建议用只读连接账号,把权限收到最小。
测试连接
text
POST /api/v1/datasources/{ds_id}/test用已保存的凭据测试连通性,返回 success / latency_ms / server_version / error_type。
列出数据源
text
GET /api/v1/datasources?page=1&size=20返回分页结果:
json
{
"items": [
{
"id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"name": "生产用户库",
"db_type": "postgresql",
"status": "connected",
"schema_count": 3,
"table_count": 48,
"field_count": 612,
"last_scan_at": "2026-05-20T08:00:00Z",
"created_at": "2026-05-19T10:12:00Z"
}
],
"total": 1,
"page": 1,
"size": 20
}建好数据源后,下一步是 触发扫描。