5.6 KiB
5.6 KiB
Схема БД
1. Назначение документа
Этот документ фиксирует целевую структуру хранения workspace-scoped конфигураций, агентов, ключей доступа и observability-данных. Базовая СУБД - PostgreSQL.
2. Общие принципы хранения
2.1. Версионирование обязательно
Конфигурация operation и agent не хранится только в одной "живой" записи. Каждое существенное изменение создает новую версию.
2.2. Published и draft разделяются логически
draftможет меняться;publishedвсегда указывает на конкретную version;- runtime читает только опубликованные представления.
2.3. Workspace scoping обязателен
Все продуктовые таблицы должны ссылаться на workspaces.
2.4. Артефакты и конфигурация не смешиваются
.proto, descriptor set, sample JSON и YAML payload не хранятся в тех же строках, что runtime-ready configuration.
2.5. Секреты не хранятся в открытом виде
- upstream secrets живут за
secret_ref; - platform API keys хранятся как hash.
3. Основные таблицы
workspacesusersmembershipsinvitation_tokensoperationsoperation_versionspublished_operationsoperation_samplesdescriptorsauth_profilesagentsagent_versionsagent_operation_bindingspublished_agentsplatform_api_keysinvocation_logsusage_rollupsyaml_import_jobs
4. Operations
operations
idworkspace_idnamedisplay_nameprotocolstatuscurrent_draft_versionlatest_published_versioncreated_atupdated_atpublished_at
Ограничение:
unique (workspace_id, name)
operation_versions
operation_idversionstatustarget_jsoninput_schema_jsonoutput_schema_jsoninput_mapping_jsonoutput_mapping_jsonexecution_config_jsontool_description_jsonsamples_jsongenerated_draft_jsonconfig_export_jsonchange_notecreated_atcreated_by
published_operations
operation_idversionpublished_atpublished_by
5. Operation artifacts
operation_samples
idoperation_idversionsample_kindstorage_refcontent_typefile_namecreated_at
descriptors
idoperation_idversiondescriptor_kindstorage_refsource_namepackage_index_jsoncreated_at
yaml_import_jobs
idsource_sample_idstatusformat_versionmoderesult_operation_idresult_versionerror_textcreated_atfinished_at
6. Upstream auth
auth_profiles
idworkspace_idnamekindconfig_jsoncreated_atupdated_at
Ограничение:
unique (workspace_id, name)
7. Workspaces and access layer
workspaces
idslugdisplay_namestatussettings_jsoncreated_atupdated_at
users
idemaildisplay_namestatuscreated_at
memberships
workspace_iduser_idrolecreated_at
invitation_tokens
idworkspace_idemailrolestatustoken_hashexpires_atcreated_at
8. Agents
agents
idworkspace_idslugdisplay_namedescriptionstatuscurrent_draft_versionlatest_published_versioncreated_atupdated_atpublished_at
Ограничение:
unique (workspace_id, slug)
agent_versions
agent_idversionstatusinstructions_jsontool_selection_policy_jsoncreated_at
agent_operation_bindings
agent_idagent_versionoperation_idoperation_versiontool_nametool_titletool_description_overrideenabled
published_agents
agent_idversionpublished_atpublished_by
9. Platform access and observability
platform_api_keys
idworkspace_idnameprefixsecret_hashscopes_jsonstatuscreated_atlast_used_at
invocation_logs
idworkspace_idagent_idoperation_idsourcerequest_idlevelstatustool_namemessagestatus_codeduration_mserror_kindrequest_preview_jsonresponse_preview_jsoncreated_at
usage_rollups
workspace_idagent_idoperation_idperiod_kindperiod_startcalls_totalcalls_okcalls_errorp50_msp95_msp99_ms
Замечание:
- в MVP usage read-model может вычисляться напрямую из
invocation_logs; usage_rollupsсохраняется как совместимая таблица под materialized aggregates и дальнейшую оптимизацию.
10. Migration strategy
Переход от текущей схемы к целевой идет так:
- добавить
workspacesи заполнить default workspace; - добавить
workspace_idвoperationsиauth_profiles; - добавить
agentsиpublished_agents; - внедрить
platform_api_keys; - добавить
invocation_logsиusage_rollups; - перевести MCP runtime на
published_agents, а не на глобальный список operations.