From 07421fdb1848b2da72bd251ae54fd596ed4f08da Mon Sep 17 00:00:00 2001 From: Per Stark Date: Fri, 2 Jan 2026 15:41:22 +0100 Subject: [PATCH] fix: schemafull and textcontent --- .../20251231_enforce_schemafull.surql | 21 +++++++++++++++++++ .../20251231_enforce_schemafull.json | 1 + common/schemas/text_content.surql | 16 +++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 common/migrations/definitions/20251231_enforce_schemafull.json diff --git a/common/migrations/20251231_enforce_schemafull.surql b/common/migrations/20251231_enforce_schemafull.surql index f957f38..d37cbe1 100644 --- a/common/migrations/20251231_enforce_schemafull.surql +++ b/common/migrations/20251231_enforce_schemafull.surql @@ -66,5 +66,26 @@ DEFINE TABLE OVERWRITE relates_to SCHEMAFULL; DEFINE TABLE OVERWRITE scratchpad SCHEMAFULL; DEFINE TABLE OVERWRITE system_settings SCHEMAFULL; DEFINE TABLE OVERWRITE text_chunk SCHEMAFULL; +-- text_content must have fields defined before enforcing SCHEMAFULL DEFINE TABLE OVERWRITE text_content SCHEMAFULL; +DEFINE FIELD IF NOT EXISTS created_at ON text_content TYPE datetime; +DEFINE FIELD IF NOT EXISTS updated_at ON text_content TYPE datetime; +DEFINE FIELD IF NOT EXISTS text ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS file_info ON text_content TYPE option; +DEFINE FIELD IF NOT EXISTS url_info ON text_content TYPE option; +DEFINE FIELD IF NOT EXISTS url_info.url ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS url_info.title ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS url_info.image_id ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS context ON text_content TYPE option; +DEFINE FIELD IF NOT EXISTS category ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS user_id ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS file_info.id ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS file_info.created_at ON text_content TYPE datetime; +DEFINE FIELD IF NOT EXISTS file_info.updated_at ON text_content TYPE datetime; +DEFINE FIELD IF NOT EXISTS file_info.sha256 ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS file_info.path ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS file_info.file_name ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS file_info.mime_type ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS file_info.user_id ON text_content TYPE string; + DEFINE TABLE OVERWRITE user SCHEMAFULL; diff --git a/common/migrations/definitions/20251231_enforce_schemafull.json b/common/migrations/definitions/20251231_enforce_schemafull.json new file mode 100644 index 0000000..3fdf054 --- /dev/null +++ b/common/migrations/definitions/20251231_enforce_schemafull.json @@ -0,0 +1 @@ +{"schemas":"--- original\n+++ modified\n@@ -242,7 +242,7 @@\n\n # Defines the schema for the 'text_content' table.\n\n-DEFINE TABLE IF NOT EXISTS text_content SCHEMALESS;\n+DEFINE TABLE IF NOT EXISTS text_content SCHEMAFULL;\n\n # Standard fields\n DEFINE FIELD IF NOT EXISTS created_at ON text_content TYPE datetime;\n@@ -254,10 +254,24 @@\n DEFINE FIELD IF NOT EXISTS file_info ON text_content TYPE option;\n # UrlInfo is a struct, store as object\n DEFINE FIELD IF NOT EXISTS url_info ON text_content TYPE option;\n+DEFINE FIELD IF NOT EXISTS url_info.url ON text_content TYPE string;\n+DEFINE FIELD IF NOT EXISTS url_info.title ON text_content TYPE string;\n+DEFINE FIELD IF NOT EXISTS url_info.image_id ON text_content TYPE string;\n+\n DEFINE FIELD IF NOT EXISTS context ON text_content TYPE option;\n DEFINE FIELD IF NOT EXISTS category ON text_content TYPE string;\n DEFINE FIELD IF NOT EXISTS user_id ON text_content TYPE string;\n\n+# FileInfo fields\n+DEFINE FIELD IF NOT EXISTS file_info.id ON text_content TYPE string;\n+DEFINE FIELD IF NOT EXISTS file_info.created_at ON text_content TYPE datetime;\n+DEFINE FIELD IF NOT EXISTS file_info.updated_at ON text_content TYPE datetime;\n+DEFINE FIELD IF NOT EXISTS file_info.sha256 ON text_content TYPE string;\n+DEFINE FIELD IF NOT EXISTS file_info.path ON text_content TYPE string;\n+DEFINE FIELD IF NOT EXISTS file_info.file_name ON text_content TYPE string;\n+DEFINE FIELD IF NOT EXISTS file_info.mime_type ON text_content TYPE string;\n+DEFINE FIELD IF NOT EXISTS file_info.user_id ON text_content TYPE string;\n+\n # Indexes based on query patterns\n DEFINE INDEX IF NOT EXISTS text_content_user_id_idx ON text_content FIELDS user_id;\n DEFINE INDEX IF NOT EXISTS text_content_created_at_idx ON text_content FIELDS created_at;\n","events":null} \ No newline at end of file diff --git a/common/schemas/text_content.surql b/common/schemas/text_content.surql index e2f7b2c..c31b129 100644 --- a/common/schemas/text_content.surql +++ b/common/schemas/text_content.surql @@ -1,6 +1,6 @@ # Defines the schema for the 'text_content' table. -DEFINE TABLE IF NOT EXISTS text_content SCHEMALESS; +DEFINE TABLE IF NOT EXISTS text_content SCHEMAFULL; # Standard fields DEFINE FIELD IF NOT EXISTS created_at ON text_content TYPE datetime; @@ -12,10 +12,24 @@ DEFINE FIELD IF NOT EXISTS text ON text_content TYPE string; DEFINE FIELD IF NOT EXISTS file_info ON text_content TYPE option; # UrlInfo is a struct, store as object DEFINE FIELD IF NOT EXISTS url_info ON text_content TYPE option; +DEFINE FIELD IF NOT EXISTS url_info.url ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS url_info.title ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS url_info.image_id ON text_content TYPE string; + DEFINE FIELD IF NOT EXISTS context ON text_content TYPE option; DEFINE FIELD IF NOT EXISTS category ON text_content TYPE string; DEFINE FIELD IF NOT EXISTS user_id ON text_content TYPE string; +# FileInfo fields +DEFINE FIELD IF NOT EXISTS file_info.id ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS file_info.created_at ON text_content TYPE datetime; +DEFINE FIELD IF NOT EXISTS file_info.updated_at ON text_content TYPE datetime; +DEFINE FIELD IF NOT EXISTS file_info.sha256 ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS file_info.path ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS file_info.file_name ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS file_info.mime_type ON text_content TYPE string; +DEFINE FIELD IF NOT EXISTS file_info.user_id ON text_content TYPE string; + # Indexes based on query patterns DEFINE INDEX IF NOT EXISTS text_content_user_id_idx ON text_content FIELDS user_id; DEFINE INDEX IF NOT EXISTS text_content_created_at_idx ON text_content FIELDS created_at;