tangle


git clone https://radroots.dev/git/tangle.git
Log | Files | Refs | README | LICENSE

commit 3eeba715a9e9671fcc1574c7ab3fde6438df6ded
parent 939974fd16371dd8fc20bcf9c242c161dc4595a0
Author: triesap <tyson@radroots.org>
Date:   Fri,  5 Jun 2026 22:36:42 -0700

migrations: add current event schema

Diffstat:
Mcrates/tangle_store_surreal/src/lib.rs | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+), 0 deletions(-)

diff --git a/crates/tangle_store_surreal/src/lib.rs b/crates/tangle_store_surreal/src/lib.rs @@ -281,6 +281,7 @@ pub fn base_migration_plan() -> SurrealMigrationPlan { migration_tracking_schema(), raw_event_schema(), event_tag_index_schema(), + current_event_schema(), ]) .expect("base migration plan is strictly ordered") } @@ -337,6 +338,29 @@ DEFINE INDEX IF NOT EXISTS event_tag_event ON TABLE event_tag_index COLUMNS even .expect("event tag index schema is valid") } +pub fn current_event_schema() -> SurrealMigration { + SurrealMigration::new( + "0004_current_event", + r#" +DEFINE TABLE IF NOT EXISTS event_current SCHEMAFULL; +DEFINE FIELD IF NOT EXISTS address_key ON TABLE event_current TYPE string; +DEFINE FIELD IF NOT EXISTS kind ON TABLE event_current TYPE int; +DEFINE FIELD IF NOT EXISTS pubkey ON TABLE event_current TYPE string; +DEFINE FIELD IF NOT EXISTS d ON TABLE event_current TYPE option<string>; +DEFINE FIELD IF NOT EXISTS event_id ON TABLE event_current TYPE string; +DEFINE FIELD IF NOT EXISTS created_at ON TABLE event_current TYPE int; +DEFINE FIELD IF NOT EXISTS tie_break_id ON TABLE event_current TYPE string; +DEFINE FIELD IF NOT EXISTS deleted ON TABLE event_current TYPE bool DEFAULT false; +DEFINE FIELD IF NOT EXISTS hidden ON TABLE event_current TYPE bool DEFAULT false; +DEFINE FIELD IF NOT EXISTS updated_at ON TABLE event_current TYPE int; +DEFINE INDEX IF NOT EXISTS event_current_address_uid ON TABLE event_current COLUMNS address_key UNIQUE; +DEFINE INDEX IF NOT EXISTS event_current_kind_pubkey ON TABLE event_current COLUMNS kind, pubkey; +DEFINE INDEX IF NOT EXISTS event_current_event ON TABLE event_current COLUMNS event_id; +"#, + ) + .expect("current event schema is valid") +} + #[derive(Debug, Clone, PartialEq, Eq)] pub struct AppliedMigration { name: String, @@ -841,4 +865,32 @@ mod tests { assert!(info.contains(expected), "missing {expected} in {info}"); } } + + #[tokio::test] + async fn current_event_schema_defines_replaceable_pointer_table() { + let store = memory_store().await; + store + .apply_plan(&base_migration_plan()) + .await + .expect("apply plan"); + let info = store.table_info("event_current").await.expect("table info"); + + for expected in [ + "address_key", + "kind", + "pubkey", + "d", + "event_id", + "created_at", + "tie_break_id", + "deleted", + "hidden", + "updated_at", + "event_current_address_uid", + "event_current_kind_pubkey", + "event_current_event", + ] { + assert!(info.contains(expected), "missing {expected} in {info}"); + } + } }