From ce8e2d4578d38b62943c4a8dcc082b78a247ac2c Mon Sep 17 00:00:00 2001 From: Raphael Darley Date: Thu, 21 Mar 2024 10:59:08 +0000 Subject: [PATCH] bugfix: Enforce `TYPE RELATION` (#3732) --- core/src/syn/v1/stmt/define/table.rs | 3 +-- core/src/syn/v2/parser/stmt/define.rs | 4 ---- lib/tests/define.rs | 2 +- lib/tests/field.rs | 2 +- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/core/src/syn/v1/stmt/define/table.rs b/core/src/syn/v1/stmt/define/table.rs index 5a028782..968a83d0 100644 --- a/core/src/syn/v1/stmt/define/table.rs +++ b/core/src/syn/v1/stmt/define/table.rs @@ -29,7 +29,7 @@ pub fn table(i: &str) -> IResult<&str, DefineTableStatement> { let (i, name) = cut(ident)(i)?; let (i, opts) = many0(table_opts)(i)?; let (i, _) = expected( - "TYPE, RELATION, DROP, SCHEMALESS, SCHEMAFUL(L), VIEW, CHANGEFEED, PERMISSIONS, or COMMENT", + "TYPE, DROP, SCHEMALESS, SCHEMAFUL(L), VIEW, CHANGEFEED, PERMISSIONS, or COMMENT", ending::query, )(i)?; // Create the base statement @@ -129,7 +129,6 @@ fn table_opts(i: &str) -> IResult<&str, DefineTableOption> { table_permissions, table_changefeed, table_type, - table_relation, ))(i) } diff --git a/core/src/syn/v2/parser/stmt/define.rs b/core/src/syn/v2/parser/stmt/define.rs index b669ea75..6e79d087 100644 --- a/core/src/syn/v2/parser/stmt/define.rs +++ b/core/src/syn/v2/parser/stmt/define.rs @@ -354,10 +354,6 @@ impl Parser<'_> { self.pop_peek(); res.drop = true; } - t!("RELATION") => { - self.pop_peek(); - res.kind = TableType::Relation(self.parse_relation_schema()?); - } t!("TYPE") => { self.pop_peek(); match self.peek_kind() { diff --git a/lib/tests/define.rs b/lib/tests/define.rs index 29fc5829..810b7b6d 100644 --- a/lib/tests/define.rs +++ b/lib/tests/define.rs @@ -2648,7 +2648,7 @@ async fn redefining_existing_user_with_if_not_exists_should_error() -> Result<() #[cfg(feature = "sql2")] async fn define_table_relation() -> Result<(), Error> { let sql = " - DEFINE TABLE likes RELATION; + DEFINE TABLE likes TYPE RELATION; CREATE person:raphael, person:tobie; RELATE person:raphael->likes->person:tobie; CREATE likes:1; diff --git a/lib/tests/field.rs b/lib/tests/field.rs index 812808dc..c45b3570 100644 --- a/lib/tests/field.rs +++ b/lib/tests/field.rs @@ -789,7 +789,7 @@ async fn field_definition_edge_permissions() -> Result<(), Error> { DEFINE TABLE user SCHEMAFULL; DEFINE TABLE business SCHEMAFULL; DEFINE FIELD owner ON TABLE business TYPE record; - DEFINE TABLE contact RELATION SCHEMAFULL PERMISSIONS FOR create WHERE in.owner.id = $auth.id; + DEFINE TABLE contact TYPE RELATION SCHEMAFULL PERMISSIONS FOR create WHERE in.owner.id = $auth.id; INSERT INTO user (id, name) VALUES (user:one, 'John'), (user:two, 'Lucy'); INSERT INTO business (id, owner) VALUES (business:one, user:one), (business:two, user:two); ";