diff --git a/catalyst-gateway/bin/src/db/event/signed_docs/full_signed_doc.rs b/catalyst-gateway/bin/src/db/event/signed_docs/full_signed_doc.rs index 05fbe85ebd0..1bf39a76d63 100644 --- a/catalyst-gateway/bin/src/db/event/signed_docs/full_signed_doc.rs +++ b/catalyst-gateway/bin/src/db/event/signed_docs/full_signed_doc.rs @@ -47,8 +47,8 @@ impl FullSignedDoc { /// Returns the document author. #[allow(dead_code)] - pub(crate) fn author(&self) -> &String { - self.body.author() + pub(crate) fn authors(&self) -> &Vec { + self.body.authors() } /// Returns the `SignedDocBody`. @@ -92,7 +92,7 @@ impl FullSignedDoc { }, Err(err) if err.is::() => { EventDB::modify(INSERT_SIGNED_DOCS, &self.postgres_db_fields()).await?; - Ok(false) + Ok(true) }, Err(err) => Err(err), } @@ -154,7 +154,7 @@ impl FullSignedDoc { *id, ver, row.try_get("type")?, - row.try_get("author")?, + row.try_get("authors")?, row.try_get("metadata")?, ), payload: row.try_get("payload")?, diff --git a/catalyst-gateway/bin/src/db/event/signed_docs/query_filter.rs b/catalyst-gateway/bin/src/db/event/signed_docs/query_filter.rs index 9948fc92b48..2f8ca4ab220 100644 --- a/catalyst-gateway/bin/src/db/event/signed_docs/query_filter.rs +++ b/catalyst-gateway/bin/src/db/event/signed_docs/query_filter.rs @@ -13,7 +13,7 @@ pub(crate) enum DocsQueryFilter { DocId(uuid::Uuid), /// Select docs with the specific `id` and `ver` field DocVer(uuid::Uuid, uuid::Uuid), - /// Select docs with the specific `author` field + /// Select docs with the specific `authors` field Author(String), } @@ -26,7 +26,7 @@ impl Display for DocsQueryFilter { Self::DocVer(id, ver) => { write!(f, "signed_docs.id = '{id}' AND signed_docs.ver = '{ver}'") }, - Self::Author(author) => write!(f, "signed_docs.author = '{author}'"), + Self::Author(author) => write!(f, "signed_docs.authors @> '{{ \"{author}\" }}'"), } } } diff --git a/catalyst-gateway/bin/src/db/event/signed_docs/signed_doc_body.rs b/catalyst-gateway/bin/src/db/event/signed_docs/signed_doc_body.rs index df85b1c40a0..1e1c6c8ac67 100644 --- a/catalyst-gateway/bin/src/db/event/signed_docs/signed_doc_body.rs +++ b/catalyst-gateway/bin/src/db/event/signed_docs/signed_doc_body.rs @@ -23,8 +23,8 @@ pub(crate) struct SignedDocBody { ver: uuid::Uuid, /// `signed_doc` table `type` field doc_type: uuid::Uuid, - /// `signed_doc` table `author` field - author: String, + /// `signed_doc` table `authors` field + authors: Vec, /// `signed_doc` table `metadata` field metadata: Option, } @@ -40,9 +40,9 @@ impl SignedDocBody { &self.ver } - /// Returns the document author. - pub(crate) fn author(&self) -> &String { - &self.author + /// Returns the document authors. + pub(crate) fn authors(&self) -> &Vec { + &self.authors } /// Returns all signed document fields for the event db queries @@ -51,22 +51,21 @@ impl SignedDocBody { &self.id, &self.ver, &self.doc_type, - &self.author, + &self.authors, &self.metadata, ] } /// Creates a `SignedDocBody` instance. - #[allow(dead_code)] pub(crate) fn new( - id: uuid::Uuid, ver: uuid::Uuid, doc_type: uuid::Uuid, author: String, + id: uuid::Uuid, ver: uuid::Uuid, doc_type: uuid::Uuid, authors: Vec, metadata: Option, ) -> Self { Self { id, ver, doc_type, - author, + authors, metadata, } } @@ -91,13 +90,13 @@ impl SignedDocBody { let id = row.try_get("id")?; let ver = row.try_get("ver")?; let doc_type = row.try_get("type")?; - let author = row.try_get("author")?; + let authors = row.try_get("authors")?; let metadata = row.try_get("metadata")?; Ok(Self { id, ver, doc_type, - author, + authors, metadata, }) } diff --git a/catalyst-gateway/bin/src/db/event/signed_docs/sql/filtered_select_signed_documents.sql.jinja b/catalyst-gateway/bin/src/db/event/signed_docs/sql/filtered_select_signed_documents.sql.jinja index 3210e1c6dff..eacbfb327d6 100644 --- a/catalyst-gateway/bin/src/db/event/signed_docs/sql/filtered_select_signed_documents.sql.jinja +++ b/catalyst-gateway/bin/src/db/event/signed_docs/sql/filtered_select_signed_documents.sql.jinja @@ -2,7 +2,7 @@ SELECT signed_docs.id, signed_docs.ver, signed_docs.type, - signed_docs.author, + signed_docs.authors, signed_docs.metadata FROM signed_docs WHERE diff --git a/catalyst-gateway/bin/src/db/event/signed_docs/sql/insert_signed_documents.sql b/catalyst-gateway/bin/src/db/event/signed_docs/sql/insert_signed_documents.sql index 61183ea693a..2f69b49efad 100644 --- a/catalyst-gateway/bin/src/db/event/signed_docs/sql/insert_signed_documents.sql +++ b/catalyst-gateway/bin/src/db/event/signed_docs/sql/insert_signed_documents.sql @@ -3,7 +3,7 @@ INSERT INTO signed_docs id, ver, type, - author, + authors, metadata, payload, raw diff --git a/catalyst-gateway/bin/src/db/event/signed_docs/sql/select_signed_documents.sql.jinja b/catalyst-gateway/bin/src/db/event/signed_docs/sql/select_signed_documents.sql.jinja index a1a16a7bcb9..386387fa7a2 100644 --- a/catalyst-gateway/bin/src/db/event/signed_docs/sql/select_signed_documents.sql.jinja +++ b/catalyst-gateway/bin/src/db/event/signed_docs/sql/select_signed_documents.sql.jinja @@ -1,7 +1,7 @@ SELECT {% if not ver %} signed_docs.ver, {% endif %} signed_docs.type, - signed_docs.author, + signed_docs.authors, signed_docs.metadata, signed_docs.payload, signed_docs.raw diff --git a/catalyst-gateway/bin/src/db/event/signed_docs/tests/mod.rs b/catalyst-gateway/bin/src/db/event/signed_docs/tests/mod.rs index bf3db76d38c..c3578f1fdb9 100644 --- a/catalyst-gateway/bin/src/db/event/signed_docs/tests/mod.rs +++ b/catalyst-gateway/bin/src/db/event/signed_docs/tests/mod.rs @@ -18,7 +18,7 @@ async fn queries_test() { uuid::Uuid::now_v7(), uuid::Uuid::now_v7(), doc_type, - "Alex".to_string(), + vec!["Alex".to_string()], Some(serde_json::Value::Null), ), Some(serde_json::Value::Null), @@ -29,7 +29,7 @@ async fn queries_test() { uuid::Uuid::now_v7(), uuid::Uuid::now_v7(), doc_type, - "Steven".to_string(), + vec!["Steven".to_string()], Some(serde_json::Value::Null), ), Some(serde_json::Value::Null), @@ -40,7 +40,7 @@ async fn queries_test() { uuid::Uuid::now_v7(), uuid::Uuid::now_v7(), doc_type, - "Sasha".to_string(), + vec!["Sasha".to_string()], None, ), None, @@ -54,7 +54,13 @@ async fn queries_test() { assert!(!doc.store().await.unwrap()); // try another doc with the same `id` and `ver` and with different other fields let another_doc = FullSignedDoc::new( - SignedDocBody::new(*doc.id(), *doc.ver(), doc_type, "Neil".to_string(), None), + SignedDocBody::new( + *doc.id(), + *doc.ver(), + doc_type, + vec!["Neil".to_string()], + None, + ), None, vec![], ); @@ -87,7 +93,7 @@ async fn queries_test() { assert!(res_docs.try_next().await.unwrap().is_none()); let mut res_docs = SignedDocBody::retrieve( - &DocsQueryFilter::Author(doc.author().clone()), + &DocsQueryFilter::Author(doc.authors().first().unwrap().clone()), &QueryLimits::ALL, ) .await diff --git a/catalyst-gateway/bin/src/service/api/documents/put_document.rs b/catalyst-gateway/bin/src/service/api/documents/put_document.rs index 830ac2087e1..882e3eae7a4 100644 --- a/catalyst-gateway/bin/src/service/api/documents/put_document.rs +++ b/catalyst-gateway/bin/src/service/api/documents/put_document.rs @@ -43,13 +43,8 @@ pub(crate) type AllResponses = WithErrorResponses; pub(crate) async fn endpoint(doc_bytes: Vec) -> AllResponses { match CatalystSignedDocument::try_from(doc_bytes.as_slice()) { Ok(doc) => { - let doc_body = SignedDocBody::new( - doc.doc_id(), - doc.doc_ver(), - doc.doc_type(), - String::new(), - None, - ); + let doc_body = + SignedDocBody::new(doc.doc_id(), doc.doc_ver(), doc.doc_type(), vec![], None); let payload = if doc.doc_content().is_json() { match serde_json::from_slice(doc.doc_content().bytes()) { diff --git a/catalyst-gateway/event-db/migrations/V2__signed_documents.sql b/catalyst-gateway/event-db/migrations/V2__signed_documents.sql index 28ff361d4a3..fba19edfa32 100644 --- a/catalyst-gateway/event-db/migrations/V2__signed_documents.sql +++ b/catalyst-gateway/event-db/migrations/V2__signed_documents.sql @@ -15,7 +15,7 @@ CREATE TABLE IF NOT EXISTS signed_docs ( id UUID NOT NULL, -- UUID v7 ver UUID NOT NULL, -- UUID v7 type UUID NOT NULL, -- UUID v4 - author TEXT NOT NULL, + authors TEXT[] NOT NULL, metadata JSONB NULL, payload JSONB NULL, raw BYTEA NOT NULL, @@ -32,8 +32,8 @@ COMMENT ON COLUMN signed_docs.ver IS 'The Signed Documents Document Version Number (ULID).'; COMMENT ON COLUMN signed_docs.type IS 'The Signed Document type identifier.'; -COMMENT ON COLUMN signed_docs.author IS -'The Primary Author of the Signed Document.'; +COMMENT ON COLUMN signed_docs.authors IS +'The Primary Author`s list of the Signed Document.'; COMMENT ON COLUMN signed_docs.metadata IS 'Extra metadata extracted from the Signed Document, and encoded as JSON.'; COMMENT ON COLUMN signed_docs.payload IS @@ -45,13 +45,13 @@ CREATE INDEX IF NOT EXISTS idx_signed_docs_type ON signed_docs (type); COMMENT ON INDEX idx_signed_docs_type IS 'Index to help finding documents by a known type faster.'; -CREATE INDEX IF NOT EXISTS idx_signed_docs_author ON signed_docs (author); -COMMENT ON INDEX idx_signed_docs_author IS -'Index to help finding documents by a known author faster.'; +CREATE INDEX IF NOT EXISTS idx_signed_docs_authors ON signed_docs (authors); +COMMENT ON INDEX idx_signed_docs_authors IS +'Index to help finding documents by a known authors faster.'; -CREATE INDEX IF NOT EXISTS idx_signed_docs_type_author ON signed_docs (type, author); -COMMENT ON INDEX idx_signed_docs_type_author IS -'Index to help finding documents by a known author for a specific document type faster.'; +CREATE INDEX IF NOT EXISTS idx_signed_docs_type_authors ON signed_docs (type, authors); +COMMENT ON INDEX idx_signed_docs_type_authors IS +'Index to help finding documents by a known authors for a specific document type faster.'; CREATE INDEX IF NOT EXISTS idx_signed_docs_metadata ON signed_docs USING gin (metadata);