Skip to content

Commit d31d0af

Browse files
committed
refactor: copy query schema from control-plane instead of generating locally
- Remove internal/chat/tools/generate/ directory (annotate.go, comments.go, main.go) - Remove go:generate directive from query.go - Taskfile copies schema.sql from control-plane repo - Schema is now generated in control-plane with enum values and rich comments
1 parent 695b849 commit d31d0af

3 files changed

Lines changed: 40 additions & 17 deletions

File tree

‎Taskfile.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ tasks:
5353
cmds:
5454
- go generate ./internal/powersync
5555
- go generate ./internal/sqlite
56-
- go generate ./internal/chat/tools
56+
- cp ../control-plane/internal/powersync/schema.sql internal/chat/tools/query_schema.sql
5757

5858
# ===========================================================================
5959
# Build

‎internal/chat/tools/query.go‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:generate go run ./generate
2-
31
package tools
42

53
import (

‎internal/chat/tools/query_schema.sql‎

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
-- Tero Local Catalog Schema
2-
-- Auto-generated with comments from control plane. DO NOT EDIT.
1+
-- Tero Client Schema
2+
-- Auto-generated from sync-rules.yaml and Postgres metadata. DO NOT EDIT.
3+
-- Run 'task generate:powersync' to regenerate.
34
--
4-
-- SQLite 3.51.1 with full support for: CTEs, window functions, JSON functions,
5-
-- RETURNING, generated columns, and all modern SQL features.
6-
--
7-
-- This is a LOCAL SQLite database synced from the Tero control plane.
5+
-- This describes the local SQLite database synced from the Tero control plane.
86
-- All data is scoped to the authenticated user's account.
97
--
108
-- Key concepts:
@@ -13,17 +11,16 @@
1311
-- policies - AI-identified waste (health checks, duplicate fields, bloat)
1412
-- *_cache - Pre-computed status and metrics (query these for current state)
1513
--
16-
-- IMPORTANT: All queries are READ-ONLY. This is a local sync of server data.
17-
14+
-- All queries are READ-ONLY. This is a local sync of server data.
1815

1916
CREATE TABLE conversation_contexts (
2017
id TEXT, -- Unique identifier
2118
account_id TEXT, -- Denormalized for tenant isolation. Auto-set via trigger from conversation.account_id.
22-
added_by TEXT, -- Who added this entity to context
19+
added_by TEXT, -- Who added this entity to context Values: user, assistant.
2320
conversation_id TEXT, -- Conversation this context belongs to
2421
created_at TEXT, -- When the entity was added to context
2522
entity_id TEXT, -- ID of the context entity
26-
entity_type TEXT -- Type of the context entity
23+
entity_type TEXT -- Type of the context entity Values: service, log_event.
2724
);
2825

2926
CREATE TABLE conversations (
@@ -33,9 +30,11 @@ CREATE TABLE conversations (
3330
title TEXT, -- AI-generated title, set after first exchange
3431
updated_at TEXT, -- When the conversation was last updated
3532
user_id TEXT, -- WorkOS user ID who owns this conversation
33+
view_id TEXT, -- If set, this conversation is for iterating on a specific view
3634
workspace_id TEXT -- Workspace this conversation belongs to
3735
);
3836

37+
-- Aggregated status for each Datadog account based on service statuses. Status progression: DISABLED (all services disabled) > INACTIVE (all services zero volume) > BROKEN (any service broken) > STALE (any service stale) > DISCOVERING (any service discovering) > ANALYZING (any service analyzing) > READY (all services ready).
3938
CREATE TABLE datadog_account_statuses_cache (
4039
id TEXT,
4140
account_id TEXT, -- Account ID (denormalized from Datadog account)
@@ -73,7 +72,7 @@ CREATE TABLE datadog_accounts (
7372
account_id TEXT, -- Parent account this configuration belongs to
7473
created_at TEXT, -- When the Datadog account was created
7574
name TEXT, -- Display name for this Datadog account
76-
site TEXT, -- Datadog site for this account (must be explicit)
75+
site TEXT, -- Datadog site for this account (must be explicit) Values: US1, US3, US5, EU1, US1_FED, AP1, AP2.
7776
updated_at TEXT -- When the Datadog account was last updated
7877
);
7978

@@ -94,7 +93,7 @@ CREATE TABLE discovery_statuses (
9493
consecutive_warnings INTEGER, -- Number of consecutive warnings (reset on success)
9594
created_at TEXT, -- When status tracking began
9695
datadog_account_id TEXT, -- Datadog account performing the discovery (FK arc with other integrations)
97-
discovery_type TEXT, -- Type of discovery operation being tracked
96+
discovery_type TEXT, -- Type of discovery operation being tracked Values: service, log_events, log_volume, service_log_volume.
9897
last_error TEXT, -- Last error message if discovery failed
9998
last_error_at TEXT, -- When the last error occurred
10099
last_warning TEXT, -- Last warning message (transient issues like rate limits)
@@ -110,16 +109,20 @@ CREATE TABLE log_event_policies (
110109
analysis TEXT, -- Category-specific analysis (only one field populated, matching category)
111110
approved_at TEXT, -- When this policy was approved by a user
112111
approved_by TEXT, -- User ID who approved this policy
112+
benefits TEXT, -- What benefits this policy provides. volume_reduction: fewer events, bytes_reduction: smaller events, signal_quality: less noise, compliance: regulatory/policy, resilience: system stability.
113113
category TEXT, -- Policy category (e.g., 'health_checks', 'pii_leakage')
114114
created_at TEXT, -- When this policy was created
115115
dismissed_at TEXT, -- When this policy was dismissed by a user
116116
dismissed_by TEXT, -- User ID who dismissed this policy
117117
log_event_id TEXT, -- The log event this policy applies to
118118
model TEXT, -- AI model that generated this policy (e.g., 'claude-sonnet-4-20250514')
119+
objectivity TEXT, -- How verifiable is this finding? factual: user can confirm by looking at the data, reasoned: requires AI judgment. Auto-set by trigger from category.
120+
risk_level TEXT, -- How bad is it if this policy is wrong? low: safe to apply, medium: review recommended, high: could break things. Set by AI per finding.
119121
updated_at TEXT, -- When this policy was last updated
120122
workspace_id TEXT -- The workspace that owns this policy
121123
);
122124

125+
-- Policy recommendations with status and estimated savings. Shows whether each policy is pending (WASTE), approved (SAVED), or rejected (DISMISSED), along with volume and bytes saved per hour.
123126
CREATE TABLE log_event_policy_statuses_cache (
124127
id TEXT,
125128
account_id TEXT, -- Account ID for tenant isolation
@@ -135,6 +138,7 @@ CREATE TABLE log_event_policy_statuses_cache (
135138
workspace_id TEXT -- The workspace that owns this policy
136139
);
137140

141+
-- Current status of each log event based on discovery and analysis state. Status progression: BROKEN (discovery errors) > SAVED (policy approved) > VALUABLE (analyzed, no issues) > WASTE (issues found, pending action) > ANALYZING (has volumes, awaiting analysis) > DISCOVERING (no volumes yet).
138142
CREATE TABLE log_event_statuses_cache (
139143
id TEXT,
140144
account_id TEXT, -- Account ID for tenant isolation
@@ -185,7 +189,7 @@ CREATE TABLE messages (
185189
conversation_id TEXT, -- Conversation this message belongs to
186190
created_at TEXT, -- When the message was created
187191
model TEXT, -- AI model that produced this message. Null for user messages.
188-
role TEXT, -- Who sent this message.
192+
role TEXT, -- Who sent this message. Values: user, assistant.
189193
stop_reason TEXT -- Why the assistant stopped: end_turn, tool_use. Null for user messages.
190194
);
191195

@@ -200,6 +204,7 @@ CREATE TABLE service_log_volumes (
200204
volume_per_hour INTEGER -- Log volume for this service during this hour
201205
);
202206

207+
-- Aggregated status for each service based on log event statuses. Status progression: DISABLED (user turned off) > INACTIVE (zero volume) > BROKEN (discovery errors) > STALE (data older than 48h) > DISCOVERING (coverage < 90%) > ANALYZING (log events being analyzed) > READY (all log events terminal).
203208
CREATE TABLE service_statuses_cache (
204209
id TEXT,
205210
account_id TEXT, -- Account ID (denormalized from service)
@@ -246,12 +251,32 @@ CREATE TABLE teams (
246251
workspace_id TEXT -- Parent workspace this team belongs to
247252
);
248253

254+
CREATE TABLE view_favorites (
255+
id TEXT, -- Unique identifier
256+
account_id TEXT, -- Denormalized for tenant isolation. Auto-set via trigger from view.account_id.
257+
created_at TEXT, -- When the view was favorited
258+
user_id TEXT, -- WorkOS user ID who favorited this view
259+
view_id TEXT -- The view being favorited
260+
);
261+
262+
CREATE TABLE views (
263+
id TEXT, -- Unique identifier
264+
account_id TEXT, -- Denormalized for tenant isolation. Auto-set via trigger from message.account_id.
265+
conversation_id TEXT, -- Denormalized from message for easier queries
266+
created_at TEXT, -- When the view was created
267+
created_by TEXT, -- WorkOS user ID who triggered this view creation
268+
entity_type TEXT, -- Which catalog entity this view queries Values: service, log_event, policy.
269+
forked_from_id TEXT, -- Parent view if this is a refinement/iteration
270+
message_id TEXT, -- Assistant message that created this view via show_view tool call
271+
query TEXT -- Raw SQL query executed against the client's local SQLite database
272+
);
273+
249274
CREATE TABLE workspaces (
250275
id TEXT, -- Unique identifier of the workspace
251276
account_id TEXT, -- Parent account this workspace belongs to
252277
created_at TEXT, -- When the workspace was created
253278
name TEXT, -- Human-readable name within the account
254-
purpose TEXT, -- Primary purpose determining evaluation strategy
279+
purpose TEXT, -- Primary purpose determining evaluation strategy Values: observability, security, compliance.
255280
updated_at TEXT -- When the workspace was last updated
256281
);
257282

0 commit comments

Comments
 (0)