mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-09-10 03:41:52 +02:00
One table versions HTTP, gRPC and WebSocket requests alike. A version stores the model's editable content — the serialized model minus model/id/timestamps/ workspace/folder/sortPriority — and is addressed by the sha256 of that document, with (model_id, content_hash) unique. Content addressing is what makes the trigger side simple: snapshot_request can be called by a send, a window blur and an idle timer on the same unedited request and leave one row behind, so no caller has to reason about whether anything changed. Dropping bookkeeping keys is what makes it stable — moving a request between folders or re-sorting it rewrites those fields and nothing else, and neither should mint a version or show up in a diff. The same rule covers all three request types because they differ only in content fields. Responses and gRPC/WebSocket connections gain a nullable version_id. Versions are local history, so ModelVersion is deliberately absent from AnyModel: no model-change rows, no frontend store bucket, no sync, no export. Retention keeps anything a response points at, plus the newest 50 per request within 30 days; request and workspace deletes cascade.
21 lines
1004 B
SQL
21 lines
1004 B
SQL
CREATE TABLE model_versions
|
|
(
|
|
id TEXT NOT NULL PRIMARY KEY,
|
|
model TEXT DEFAULT 'model_version' NOT NULL,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
workspace_id TEXT NOT NULL,
|
|
model_type TEXT NOT NULL,
|
|
model_id TEXT NOT NULL,
|
|
content_hash TEXT NOT NULL,
|
|
document TEXT NOT NULL,
|
|
reason TEXT NOT NULL
|
|
);
|
|
|
|
-- Content addressing, enforced by the database rather than by every caller.
|
|
CREATE UNIQUE INDEX model_versions_content ON model_versions (model_id, content_hash);
|
|
|
|
ALTER TABLE http_responses ADD COLUMN version_id TEXT;
|
|
ALTER TABLE grpc_connections ADD COLUMN version_id TEXT;
|
|
ALTER TABLE websocket_connections ADD COLUMN version_id TEXT;
|