Skip to content

Database Schema

zhouning edited this page Mar 22, 2026 · 1 revision

数据库架构 / Database Schema

中英双语 | Bilingual


中文

概览

GIS Data Agent 使用 PostgreSQL 16 + PostGIS 3.4,包含 37+ 系统表30 个迁移脚本

表清单(按领域分组)

领域 表名 说明
认证 users, sessions 用户账号和会话
数据 table_ownership, data_catalog, data_lineage 表所有权、数据目录、血缘追踪
语义 semantic_annotations, semantic_sources, semantic_domains 语义标注和领域层级
技能 agent_custom_skills, agent_skill_bundles 自定义技能和技能包
工具 agent_user_tools 用户自定义工具
工作流 agent_workflows, workflow_runs 工作流定义和执行记录
知识库 knowledge_bases, kb_documents, kb_chunks 知识库、文档、分块向量
团队 teams, team_members 团队和成员
MCP mcp_servers MCP 服务器配置
流式 stream_configs, stream_data 实时流配置和数据
审计 audit_log, token_usage 审计日志和 Token 用量
记忆 user_memories 用户持久化记忆
其他 templates, share_links, map_annotations, virtual_sources, pipeline_analytics, agent_registry, task_queue 模板/共享/标注/虚拟源/分析/注册/任务

数据库迁移

30 个 SQL 脚本位于 data_agent/migrations/,按编号顺序执行:

for f in data_agent/migrations/*.sql; do psql -U agent_user -d gis_agent -f "$f"; done

关键迁移:

  • 001_create_tables.sql — 基础表创建
  • 004_enable_rls.sql — 行级安全策略(166 行,多租户隔离核心)
  • 014_create_data_catalog.sql — 数据目录表
  • 012_create_teams.sql — 团队协作表

RLS(行级安全)

迁移 004 启用了 PostgreSQL RLS,通过 SET app.current_user 注入当前用户上下文,实现多租户数据隔离。


English

Overview

GIS Data Agent uses PostgreSQL 16 + PostGIS 3.4 with 37+ system tables and 30 migration scripts.

Table Inventory (by Domain)

Domain Tables Purpose
Auth users, sessions User accounts and sessions
Data table_ownership, data_catalog, data_lineage Table ownership, catalog, lineage tracking
Semantic semantic_annotations, semantic_sources, semantic_domains Semantic annotations and domain hierarchies
Skills agent_custom_skills, agent_skill_bundles Custom skills and bundles
Tools agent_user_tools User-defined tools
Workflows agent_workflows, workflow_runs Workflow definitions and execution records
Knowledge knowledge_bases, kb_documents, kb_chunks Knowledge bases, documents, vector chunks
Teams teams, team_members Teams and membership
MCP mcp_servers MCP server configurations
Streaming stream_configs, stream_data Real-time stream configs and data
Audit audit_log, token_usage Audit logs and token usage
Memory user_memories Persistent user memories
Other templates, share_links, map_annotations, virtual_sources, pipeline_analytics, agent_registry, task_queue Templates, sharing, annotations, virtual sources, analytics, registry, tasks

Running Migrations

30 SQL scripts in data_agent/migrations/, run in order:

for f in data_agent/migrations/*.sql; do psql -U agent_user -d gis_agent -f "$f"; done

Key migrations:

  • 001_create_tables.sql — Base table creation
  • 004_enable_rls.sql — Row-Level Security policies (166 lines, multi-tenant isolation)
  • 014_create_data_catalog.sql — Data catalog tables
  • 012_create_teams.sql — Team collaboration tables

RLS (Row-Level Security)

Migration 004 enables PostgreSQL RLS with SET app.current_user injected per-query for multi-tenant data isolation.

Clone this wiki locally