database.proto 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. // Smartbotic Database Service
  2. // Document-oriented storage with persistence and replication
  3. syntax = "proto3";
  4. package smartbotic.databasepb;
  5. // Error code range: 6000-6999 for Database errors
  6. // 6000: Generic database error
  7. // 6001: Collection not found
  8. // 6002: Document not found
  9. // 6003: Document already exists
  10. // 6004: Version conflict
  11. // 6005: Invalid query
  12. // 6006: File not found
  13. // 6007: File too large
  14. // 6008: Encryption error
  15. // 6009: Replication error
  16. // 6010: Version not found
  17. // ===== Main Database Service =====
  18. service DatabaseService {
  19. // Document operations
  20. rpc Insert(InsertRequest) returns (InsertResponse);
  21. rpc Get(GetRequest) returns (GetResponse);
  22. rpc Update(UpdateRequest) returns (UpdateResponse);
  23. rpc Upsert(UpsertRequest) returns (UpsertResponse);
  24. rpc Delete(DeleteRequest) returns (DeleteResponse);
  25. rpc PatchDocument(PatchDocumentRequest) returns (PatchDocumentResponse);
  26. rpc Exists(ExistsRequest) returns (ExistsResponse);
  27. // Version history operations
  28. rpc GetVersionHistory(GetVersionHistoryRequest) returns (GetVersionHistoryResponse);
  29. rpc GetDocumentVersion(GetDocumentVersionRequest) returns (GetDocumentVersionResponse);
  30. rpc RestoreVersion(RestoreVersionRequest) returns (RestoreVersionResponse);
  31. rpc RestoreToDate(RestoreToDateRequest) returns (RestoreToDateResponse);
  32. // Batch operations
  33. rpc BatchInsert(BatchInsertRequest) returns (BatchInsertResponse);
  34. rpc BatchGet(BatchGetRequest) returns (BatchGetResponse);
  35. rpc BatchDelete(BatchDeleteRequest) returns (BatchDeleteResponse);
  36. // Query operations
  37. rpc Find(FindRequest) returns (FindResponse);
  38. rpc Count(CountRequest) returns (CountResponse);
  39. rpc SimilaritySearch(SimilaritySearchRequest) returns (SimilaritySearchResponse);
  40. // Set operations (Redis compatibility)
  41. rpc SetAdd(SetAddRequest) returns (SetAddResponse);
  42. rpc SetRemove(SetRemoveRequest) returns (SetRemoveResponse);
  43. rpc SetMembers(SetMembersRequest) returns (SetMembersResponse);
  44. rpc SetIsMember(SetIsMemberRequest) returns (SetIsMemberResponse);
  45. // Collection management
  46. rpc CreateCollection(CreateCollectionRequest) returns (CreateCollectionResponse);
  47. rpc DropCollection(DropCollectionRequest) returns (DropCollectionResponse);
  48. rpc ListCollections(ListCollectionsRequest) returns (ListCollectionsResponse);
  49. rpc GetCollectionInfo(GetCollectionInfoRequest) returns (GetCollectionInfoResponse);
  50. // View management
  51. rpc CreateView(CreateViewRequest) returns (CreateViewResponse);
  52. rpc DropView(DropViewRequest) returns (DropViewResponse);
  53. rpc ListViews(ListViewsRequest) returns (ListViewsResponse);
  54. rpc GetViewInfo(GetViewInfoRequest) returns (GetViewInfoResponse);
  55. // Collection configuration
  56. rpc ConfigureCollection(ConfigureCollectionRequest) returns (ConfigureCollectionResponse);
  57. rpc GetCollectionConfig(GetCollectionConfigRequest) returns (GetCollectionConfigResponse);
  58. rpc MigrateCollectionTimestamps(MigrateCollectionTimestampsRequest) returns (MigrateCollectionTimestampsResponse);
  59. // File operations
  60. rpc UploadFile(stream FileChunk) returns (UploadFileResponse);
  61. rpc DownloadFile(DownloadFileRequest) returns (stream FileChunk);
  62. rpc DeleteFile(DeleteFileRequest) returns (DeleteFileResponse);
  63. rpc GetFileInfo(GetFileInfoRequest) returns (FileInfo);
  64. rpc ListFiles(ListFilesRequest) returns (ListFilesResponse);
  65. // Event subscription
  66. rpc Subscribe(SubscribeRequest) returns (stream DatabaseEvent);
  67. // Health and stats
  68. rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse);
  69. rpc GetStats(GetStatsRequest) returns (GetStatsResponse);
  70. // Read-only runtime state control
  71. rpc SetReadOnly(SetReadOnlyRequest) returns (SetReadOnlyResponse);
  72. rpc GetReadOnlyStatus(GetReadOnlyStatusRequest) returns (GetReadOnlyStatusResponse);
  73. }
  74. // ===== Replication Service =====
  75. service DatabaseReplication {
  76. // Bidirectional streaming for real-time sync
  77. rpc SyncStream(stream ReplicationMessage) returns (stream ReplicationMessage);
  78. // Pull missed entries (for recovery)
  79. rpc GetEntriesSince(GetEntriesRequest) returns (stream ReplicationEntry);
  80. // Get current node state
  81. rpc GetNodeState(GetNodeStateRequest) returns (NodeState);
  82. }
  83. // ===== Document Types =====
  84. message Document {
  85. string id = 1;
  86. string collection = 2;
  87. bytes data = 3; // JSON-encoded document data
  88. uint64 version = 4;
  89. uint64 created_at = 5; // Timestamp in milliseconds
  90. uint64 updated_at = 6;
  91. uint64 expires_at = 7; // 0 = no expiration
  92. string node_id = 8; // Origin node for replication
  93. bool encrypted = 9;
  94. repeated string encrypted_fields = 10;
  95. string created_by = 11; // User ID who created the document
  96. string updated_by = 12; // User ID who last updated the document
  97. }
  98. // ===== Document Operations =====
  99. message InsertRequest {
  100. string collection = 1;
  101. bytes data = 2; // JSON document
  102. string id = 3; // Optional, auto-generated if empty
  103. uint32 ttl_seconds = 4; // 0 = use collection default
  104. string actor = 5; // User ID performing the operation (for audit)
  105. }
  106. message InsertResponse {
  107. string id = 1;
  108. uint64 version = 2;
  109. }
  110. message GetRequest {
  111. string collection = 1;
  112. string id = 2;
  113. }
  114. message GetResponse {
  115. Document document = 1;
  116. bool found = 2;
  117. }
  118. message UpdateRequest {
  119. string collection = 1;
  120. string id = 2;
  121. bytes data = 3;
  122. uint64 expected_version = 4; // 0 = no version check (force update)
  123. string actor = 5; // User ID performing the operation (for audit)
  124. }
  125. message UpdateResponse {
  126. uint64 new_version = 1;
  127. bool success = 2;
  128. string error = 3;
  129. }
  130. message UpsertRequest {
  131. string collection = 1;
  132. bytes data = 2;
  133. string id = 3;
  134. uint32 ttl_seconds = 4;
  135. string actor = 5; // User ID performing the operation (for audit)
  136. }
  137. message UpsertResponse {
  138. string id = 1;
  139. uint64 version = 2;
  140. bool inserted = 3; // true if inserted, false if updated
  141. }
  142. message DeleteRequest {
  143. string collection = 1;
  144. string id = 2;
  145. }
  146. message DeleteResponse {
  147. bool deleted = 1;
  148. }
  149. message PatchDocumentRequest {
  150. string collection = 1;
  151. string id = 2;
  152. bytes patch_json = 3; // JSON fields to merge into existing document
  153. string actor = 4; // User ID performing the operation (for audit)
  154. }
  155. message PatchDocumentResponse {
  156. uint64 new_version = 1;
  157. bool success = 2;
  158. string error = 3;
  159. }
  160. message ExistsRequest {
  161. string collection = 1;
  162. string id = 2;
  163. }
  164. message ExistsResponse {
  165. bool exists = 1;
  166. }
  167. // ===== Version History Operations =====
  168. message DocumentVersionEntry {
  169. uint64 version = 1;
  170. bytes data = 2; // JSON-encoded document data at this version
  171. uint64 timestamp = 3; // When this version was created (updatedAt)
  172. string updated_by = 4;
  173. bool encrypted = 5;
  174. repeated string encrypted_fields = 6;
  175. }
  176. message GetVersionHistoryRequest {
  177. string collection = 1;
  178. string id = 2;
  179. uint32 limit = 3; // 0 = all versions
  180. uint32 offset = 4;
  181. }
  182. message GetVersionHistoryResponse {
  183. repeated DocumentVersionEntry versions = 1;
  184. uint64 current_version = 2; // 0 if document is deleted
  185. uint64 total_count = 3;
  186. bool document_deleted = 4;
  187. }
  188. message GetDocumentVersionRequest {
  189. string collection = 1;
  190. string id = 2;
  191. uint64 version = 3;
  192. }
  193. message GetDocumentVersionResponse {
  194. DocumentVersionEntry version_entry = 1;
  195. bool found = 2;
  196. }
  197. message RestoreVersionRequest {
  198. string collection = 1;
  199. string id = 2;
  200. uint64 version = 3; // Version number to restore
  201. string actor = 4; // User performing the restore
  202. }
  203. message RestoreVersionResponse {
  204. uint64 new_version = 1; // The newly created version number
  205. bool success = 2;
  206. string error = 3;
  207. }
  208. message RestoreToDateRequest {
  209. string collection = 1;
  210. string id = 2;
  211. uint64 timestamp = 3; // Find version active at this time (ms since epoch)
  212. string actor = 4;
  213. }
  214. message RestoreToDateResponse {
  215. uint64 restored_version = 1; // Which old version was restored from
  216. uint64 new_version = 2; // The newly created version number
  217. bool success = 3;
  218. string error = 4;
  219. }
  220. // ===== Batch Operations =====
  221. message BatchInsertRequest {
  222. string collection = 1;
  223. repeated BatchInsertItem items = 2;
  224. string actor = 3; // User ID performing the operation (for audit)
  225. }
  226. message BatchInsertItem {
  227. bytes data = 1;
  228. string id = 2;
  229. uint32 ttl_seconds = 3;
  230. }
  231. message BatchInsertResponse {
  232. repeated string ids = 1;
  233. uint32 success_count = 2;
  234. uint32 error_count = 3;
  235. }
  236. message BatchGetRequest {
  237. string collection = 1;
  238. repeated string ids = 2;
  239. }
  240. message BatchGetResponse {
  241. repeated Document documents = 1;
  242. }
  243. message BatchDeleteRequest {
  244. string collection = 1;
  245. repeated string ids = 2;
  246. }
  247. message BatchDeleteResponse {
  248. uint64 deleted_count = 1;
  249. }
  250. // ===== Query Operations =====
  251. message FindRequest {
  252. string collection = 1;
  253. repeated Filter filters = 2;
  254. Sort sort = 3;
  255. uint32 limit = 4; // Default 100
  256. uint32 offset = 5;
  257. repeated string projection = 6; // Fields to include (empty = all)
  258. }
  259. message Filter {
  260. string field = 1;
  261. FilterOp op = 2;
  262. bytes value = 3; // JSON-encoded value
  263. }
  264. enum FilterOp {
  265. FILTER_OP_UNSPECIFIED = 0;
  266. FILTER_OP_EQ = 1;
  267. FILTER_OP_NE = 2;
  268. FILTER_OP_GT = 3;
  269. FILTER_OP_GTE = 4;
  270. FILTER_OP_LT = 5;
  271. FILTER_OP_LTE = 6;
  272. FILTER_OP_IN = 7;
  273. FILTER_OP_CONTAINS = 8;
  274. FILTER_OP_EXISTS = 9;
  275. FILTER_OP_REGEX = 10;
  276. FILTER_OP_SEARCH = 11; // Full-text search across ID and string fields
  277. }
  278. message Sort {
  279. string field = 1;
  280. bool descending = 2;
  281. }
  282. message FindResponse {
  283. repeated Document documents = 1;
  284. uint64 total_count = 2;
  285. bool has_more = 3;
  286. // WAL fallback metrics (for queries that include evicted documents)
  287. bool used_wal_fallback = 4; // True if WAL was scanned for evicted docs
  288. uint32 memory_match_count = 5; // Documents matched from memory
  289. uint32 wal_match_count = 6; // Documents matched from WAL
  290. uint64 memory_search_micros = 7; // Time spent searching memory (µs)
  291. uint64 wal_search_micros = 8; // Time spent loading/searching WAL (µs)
  292. }
  293. message CountRequest {
  294. string collection = 1;
  295. repeated Filter filters = 2;
  296. }
  297. message CountResponse {
  298. uint64 count = 1;
  299. }
  300. message SimilaritySearchRequest {
  301. string collection = 1;
  302. repeated float query_vector = 2;
  303. uint32 top_k = 3;
  304. float min_score = 4;
  305. }
  306. message SimilaritySearchResponse {
  307. repeated SimilarityResult results = 1;
  308. }
  309. message SimilarityResult {
  310. string id = 1;
  311. float score = 2;
  312. bytes data = 3;
  313. }
  314. // ===== Set Operations =====
  315. message SetAddRequest {
  316. string collection = 1;
  317. string set_id = 2;
  318. string member = 3;
  319. }
  320. message SetAddResponse {
  321. bool added = 1; // false if already exists
  322. }
  323. message SetRemoveRequest {
  324. string collection = 1;
  325. string set_id = 2;
  326. string member = 3;
  327. }
  328. message SetRemoveResponse {
  329. bool removed = 1;
  330. }
  331. message SetMembersRequest {
  332. string collection = 1;
  333. string set_id = 2;
  334. }
  335. message SetMembersResponse {
  336. repeated string members = 1;
  337. }
  338. message SetIsMemberRequest {
  339. string collection = 1;
  340. string set_id = 2;
  341. string member = 3;
  342. }
  343. message SetIsMemberResponse {
  344. bool is_member = 1;
  345. }
  346. // ===== Collection Management =====
  347. message CreateCollectionRequest {
  348. string name = 1;
  349. CollectionOptions options = 2;
  350. }
  351. message CollectionOptions {
  352. bool auto_create_id = 1;
  353. uint32 default_ttl_seconds = 2;
  354. bool encrypted = 3;
  355. repeated string sensitive_fields = 4;
  356. uint32 max_versions = 5; // Max version history per document (0 = unlimited)
  357. uint32 vector_dimension = 6; // Dimension of vectors stored in this collection (0 = not a vector collection)
  358. }
  359. message CreateCollectionResponse {
  360. bool created = 1;
  361. }
  362. message DropCollectionRequest {
  363. string name = 1;
  364. }
  365. message DropCollectionResponse {
  366. bool dropped = 1;
  367. }
  368. message ListCollectionsRequest {
  369. }
  370. message ListCollectionsResponse {
  371. repeated string names = 1;
  372. }
  373. message GetCollectionInfoRequest {
  374. string name = 1;
  375. }
  376. message GetCollectionInfoResponse {
  377. CollectionInfo info = 1;
  378. bool found = 2;
  379. }
  380. message CollectionInfo {
  381. string name = 1;
  382. uint64 document_count = 2;
  383. uint64 size_bytes = 3;
  384. CollectionOptions options = 4;
  385. uint64 created_at = 5;
  386. uint64 updated_at = 6;
  387. uint32 vector_dimension = 7; // Dimension of vectors stored in this collection (0 = not a vector collection)
  388. }
  389. // ===== File Operations =====
  390. message FileChunk {
  391. oneof content {
  392. FileMetadata metadata = 1; // First chunk includes metadata
  393. bytes data = 2; // Subsequent chunks are data
  394. }
  395. }
  396. message FileMetadata {
  397. string id = 1; // Set by server on upload response
  398. string name = 2;
  399. string mime_type = 3;
  400. uint64 size = 4;
  401. string file_type = 5; // "plugin", "document", "generated"
  402. string related_id = 6; // plugin_id, conversation_id, etc.
  403. map<string, string> metadata = 7; // Custom metadata
  404. bool is_public = 8; // Visibility flag
  405. }
  406. message UploadFileResponse {
  407. string id = 1;
  408. uint64 size = 2;
  409. string checksum = 3; // SHA-256
  410. bool deduplicated = 4; // True if blob already existed
  411. }
  412. message DownloadFileRequest {
  413. string id = 1;
  414. }
  415. message DeleteFileRequest {
  416. string id = 1;
  417. }
  418. message DeleteFileResponse {
  419. bool deleted = 1;
  420. }
  421. message GetFileInfoRequest {
  422. string id = 1;
  423. }
  424. message FileInfo {
  425. string id = 1;
  426. string name = 2;
  427. string mime_type = 3;
  428. uint64 size = 4;
  429. string file_type = 5;
  430. string related_id = 6;
  431. string checksum = 7;
  432. uint64 created_at = 8;
  433. map<string, string> metadata = 9;
  434. bool is_public = 10; // Visibility flag
  435. uint32 ref_count = 11; // Blob reference count (informational)
  436. }
  437. message ListFilesRequest {
  438. string file_type = 1; // Filter by type (optional)
  439. string related_id = 2; // Filter by related ID (optional)
  440. uint32 limit = 3;
  441. uint32 offset = 4;
  442. string checksum = 5; // Filter by checksum (for dedup queries)
  443. string name = 6; // Filter by exact filename (optional)
  444. }
  445. message ListFilesResponse {
  446. repeated FileInfo files = 1;
  447. uint64 total_count = 2;
  448. bool has_more = 3;
  449. }
  450. // ===== Event Subscription =====
  451. message SubscribeRequest {
  452. repeated string collections = 1; // Empty = all collections
  453. repeated string patterns = 2; // Glob patterns (e.g., "assistants:*")
  454. bool include_data = 3; // Include document data in events
  455. }
  456. message DatabaseEvent {
  457. EventType type = 1;
  458. string collection = 2;
  459. string document_id = 3;
  460. uint64 timestamp = 4;
  461. string node_id = 5;
  462. bytes data = 6; // JSON document (if include_data)
  463. }
  464. enum EventType {
  465. EVENT_UNKNOWN = 0;
  466. EVENT_INSERT = 1;
  467. EVENT_UPDATE = 2;
  468. EVENT_DELETE = 3;
  469. EVENT_EXPIRE = 4;
  470. EVENT_INVALIDATE = 5;
  471. }
  472. // ===== Replication =====
  473. message ReplicationEntry {
  474. uint64 sequence = 1;
  475. uint64 global_timestamp = 2;
  476. string node_id = 3;
  477. OperationType op = 4;
  478. string collection = 5;
  479. string document_id = 6;
  480. uint64 document_version = 7;
  481. bytes data = 8;
  482. }
  483. enum OperationType {
  484. OP_UNKNOWN = 0;
  485. OP_INSERT = 1;
  486. OP_UPDATE = 2;
  487. OP_DELETE = 3;
  488. OP_UPSERT = 4;
  489. OP_CREATE_COLLECTION = 5;
  490. OP_DROP_COLLECTION = 6;
  491. }
  492. message ReplicationMessage {
  493. oneof content {
  494. ReplicationEntry entry = 1;
  495. Heartbeat heartbeat = 2;
  496. WatermarkUpdate watermark = 3;
  497. SyncRequest sync_request = 4;
  498. }
  499. }
  500. message Heartbeat {
  501. string node_id = 1;
  502. uint64 timestamp = 2;
  503. uint64 sequence = 3;
  504. }
  505. message WatermarkUpdate {
  506. string node_id = 1;
  507. uint64 sequence = 2;
  508. }
  509. message SyncRequest {
  510. uint64 from_sequence = 1;
  511. }
  512. message GetEntriesRequest {
  513. uint64 from_sequence = 1;
  514. uint32 limit = 2;
  515. }
  516. message GetNodeStateRequest {
  517. }
  518. message NodeState {
  519. string node_id = 1;
  520. uint64 current_sequence = 2;
  521. map<string, uint64> peer_watermarks = 3;
  522. uint64 document_count = 4;
  523. repeated string collections = 5;
  524. bool healthy = 6;
  525. // Per-collection sequence tracking for collection discovery
  526. map<string, uint64> collection_sequences = 7;
  527. }
  528. // ===== Health and Stats =====
  529. message HealthCheckRequest {
  530. }
  531. message HealthCheckResponse {
  532. bool healthy = 1;
  533. uint64 uptime_seconds = 2;
  534. uint64 document_count = 3;
  535. uint64 memory_used_bytes = 4;
  536. uint64 wal_size_bytes = 5;
  537. repeated PeerHealth peers = 6;
  538. }
  539. message PeerHealth {
  540. string node_id = 1;
  541. bool connected = 2;
  542. uint64 latency_ms = 3;
  543. uint64 lag_entries = 4;
  544. }
  545. message GetStatsRequest {
  546. }
  547. message GetStatsResponse {
  548. uint64 total_documents = 1;
  549. uint64 total_collections = 2;
  550. uint64 memory_used_bytes = 3;
  551. uint64 wal_sequence = 4;
  552. uint64 wal_size_bytes = 5;
  553. uint64 snapshot_count = 6;
  554. uint64 last_snapshot_sequence = 7;
  555. uint64 insert_count = 8;
  556. uint64 update_count = 9;
  557. uint64 delete_count = 10;
  558. uint64 query_count = 11;
  559. // Memory eviction stats
  560. uint64 evicted_documents = 12; // Documents currently evicted to disk
  561. uint64 total_evictions = 13; // Total eviction operations performed
  562. uint64 recovery_count = 14; // Documents recovered from eviction
  563. // Memory configuration
  564. uint64 max_memory_bytes = 15; // Configured max memory limit
  565. uint32 eviction_threshold_percent = 16; // Start evicting at this % of max
  566. uint32 eviction_target_percent = 17; // Evict down to this % of max
  567. // Operation timing (microseconds) - for performance monitoring
  568. uint64 get_count = 18; // Number of get operations
  569. uint64 get_total_micros = 19; // Total time spent in get operations
  570. uint64 get_max_micros = 20; // Max single get operation time
  571. uint64 insert_total_micros = 21;
  572. uint64 insert_max_micros = 22;
  573. uint64 update_total_micros = 23;
  574. uint64 update_max_micros = 24;
  575. uint64 query_total_micros = 25;
  576. uint64 query_max_micros = 26;
  577. }
  578. // ===== View Operations =====
  579. message ViewDefinition {
  580. string name = 1; // view name (globally unique, cannot start with _)
  581. string collection = 2; // target real collection (must NOT be another view)
  582. repeated string include = 3; // field paths to include (dot-notation for nested)
  583. repeated string exclude = 4; // field paths to exclude (ignored if include is non-empty)
  584. repeated Filter where = 5; // baked-in filters (AND-merged with caller filters)
  585. Sort default_sort = 6; // baked-in default sort (used when caller doesn't specify)
  586. uint64 created_at = 7;
  587. uint64 updated_at = 8;
  588. }
  589. message CreateViewRequest {
  590. string name = 1;
  591. string collection = 2;
  592. repeated string include = 3;
  593. repeated string exclude = 4;
  594. repeated Filter where = 5;
  595. Sort default_sort = 6;
  596. }
  597. message CreateViewResponse {
  598. bool success = 1;
  599. string error = 2;
  600. }
  601. message DropViewRequest {
  602. string name = 1;
  603. }
  604. message DropViewResponse {
  605. bool success = 1;
  606. string error = 2;
  607. }
  608. message ListViewsRequest {}
  609. message ListViewsResponse {
  610. repeated ViewDefinition views = 1;
  611. }
  612. message GetViewInfoRequest {
  613. string name = 1;
  614. }
  615. message GetViewInfoResponse {
  616. ViewDefinition view = 1;
  617. bool found = 2;
  618. }
  619. // ===== Collection Configuration =====
  620. // Per-collection configuration for timestamp precision and other runtime knobs.
  621. // Stored in the _collection_meta system collection.
  622. message CollectionConfig {
  623. // "ms" (default) — _created_at/_updated_at stamped in milliseconds since epoch
  624. // "ns" — _created_at/_updated_at stamped in nanoseconds since epoch
  625. string timestamp_precision = 1;
  626. // Room for future per-collection knobs
  627. }
  628. message ConfigureCollectionRequest {
  629. string collection = 1;
  630. CollectionConfig config = 2;
  631. }
  632. message ConfigureCollectionResponse {
  633. bool success = 1;
  634. string error = 2;
  635. }
  636. message GetCollectionConfigRequest {
  637. string collection = 1;
  638. }
  639. message GetCollectionConfigResponse {
  640. CollectionConfig config = 1;
  641. bool found = 2;
  642. }
  643. message MigrateCollectionTimestampsRequest {
  644. string collection = 1;
  645. string from_precision = 2; // "ms" or "ns"
  646. string to_precision = 3; // "ms" or "ns"
  647. }
  648. message MigrateCollectionTimestampsResponse {
  649. bool success = 1;
  650. string error = 2;
  651. uint64 rows_migrated = 3; // how many documents had their timestamps updated
  652. uint64 rows_skipped = 4; // already in target range (idempotent resume)
  653. }
  654. // ===== Read-Only Control =====
  655. message SetReadOnlyRequest {
  656. bool read_only = 1;
  657. }
  658. message SetReadOnlyResponse {
  659. bool success = 1;
  660. bool was_read_only = 2; // previous state
  661. string error = 3;
  662. }
  663. message GetReadOnlyStatusRequest {}
  664. message GetReadOnlyStatusResponse {
  665. bool read_only = 1;
  666. string reason = 2;
  667. // Recovery outcome details (populated when auto-readonly triggered)
  668. string recovery_outcome = 3; // "trivial_success" | "fresh_install" | "snapshot_fell_back" | "wal_only_replay" | "forced_empty" | "failed"
  669. string expected_snapshot = 4;
  670. string snapshot_used = 5;
  671. string failure_reason = 6;
  672. uint64 wal_entries_replayed = 7;
  673. uint32 snapshots_attempted = 8;
  674. }