数据源

登记数据库连接、测试连通性、列出已有数据源。数据源是扫描与分级的入口。

数据源(datasource)代表一个待分类的数据库连接。建好之后,对它发起扫描即可逐字段定级。

创建数据源

text
POST /api/v1/datasources

superadmin / admin / dba 角色。

请求体

字段类型必填说明
namestring数据源显示名
db_typestring数据库类型,如 postgresql / mysql / oracle / dm(达梦)
hoststring主机地址
portint端口
databasestring库名
usernamestring连接用户名
passwordstring连接密码
ssl_enabledbool是否启用 SSL
import_modestring接入方式
freshness_threshold_daysint数据新鲜度阈值(天)

响应

字段类型说明
idUUID数据源 ID
namestring名称
db_typestring数据库类型
statusstring连接状态
schema_countint已发现 schema 数
table_countint已发现表数
field_countint已发现字段数
last_scan_atdatetime | null上次扫描时间
created_atdatetime创建时间

示例

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
}

建好数据源后,下一步是 触发扫描