database.proto 21 KB

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