SCHEMAFULL table should be TYPE NORMAL by default (#4558)

This commit is contained in:
Micha de Vries 2024-08-21 09:23:56 +01:00 committed by GitHub
parent 1f6e6fcfc5
commit e25eca71d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 11 deletions

View file

@ -293,8 +293,8 @@ mod tests {
#[test]
fn pretty_define_query() {
let query = parse("DEFINE TABLE test SCHEMAFULL PERMISSIONS FOR create, update, delete NONE FOR select WHERE public = true;").unwrap();
assert_eq!(format!("{}", query), "DEFINE TABLE test TYPE ANY SCHEMAFULL PERMISSIONS FOR select WHERE public = true, FOR create, update, delete NONE;");
assert_eq!(format!("{:#}", query), "DEFINE TABLE test TYPE ANY SCHEMAFULL\n\tPERMISSIONS\n\t\tFOR select\n\t\t\tWHERE public = true\n\t\tFOR create, update, delete NONE\n;");
assert_eq!(format!("{}", query), "DEFINE TABLE test TYPE NORMAL SCHEMAFULL PERMISSIONS FOR select WHERE public = true, FOR create, update, delete NONE;");
assert_eq!(format!("{:#}", query), "DEFINE TABLE test TYPE NORMAL SCHEMAFULL\n\tPERMISSIONS\n\t\tFOR select\n\t\t\tWHERE public = true\n\t\tFOR create, update, delete NONE\n;");
}
#[test]

View file

@ -646,6 +646,8 @@ impl Parser<'_> {
..Default::default()
};
let mut kind: Option<TableType> = None;
loop {
match self.peek_kind() {
t!("COMMENT") => {
@ -661,15 +663,15 @@ impl Parser<'_> {
match self.peek_kind() {
t!("NORMAL") => {
self.pop_peek();
res.kind = TableType::Normal;
kind = Some(TableType::Normal);
}
t!("RELATION") => {
self.pop_peek();
res.kind = TableType::Relation(self.parse_relation_schema()?);
kind = Some(TableType::Relation(self.parse_relation_schema()?));
}
t!("ANY") => {
self.pop_peek();
res.kind = TableType::Any;
kind = Some(TableType::Any);
}
x => unexpected!(self, x, "`NORMAL`, `RELATION`, or `ANY`"),
}
@ -681,6 +683,9 @@ impl Parser<'_> {
t!("SCHEMAFULL") => {
self.pop_peek();
res.full = true;
if kind.is_none() {
kind = Some(TableType::Normal);
}
}
t!("PERMISSIONS") => {
self.pop_peek();
@ -708,6 +713,10 @@ impl Parser<'_> {
}
}
if let Some(kind) = kind {
res.kind = kind;
}
Ok(res)
}

View file

@ -1410,7 +1410,7 @@ fn parse_define_table() {
comment: None,
if_not_exists: false,
overwrite: false,
kind: TableType::Any,
kind: TableType::Normal,
}))
);
}

View file

@ -279,7 +279,7 @@ fn statements() -> Vec<Statement> {
comment: None,
if_not_exists: false,
overwrite: false,
kind: TableType::Any,
kind: TableType::Normal,
})),
Statement::Define(DefineStatement::Event(DefineEventStatement {
name: Ident("event".to_owned()),

View file

@ -179,7 +179,7 @@ async fn define_statement_table_schemafull() -> Result<(), Error> {
functions: {},
models: {},
params: {},
tables: { test: 'DEFINE TABLE test TYPE ANY SCHEMAFULL PERMISSIONS NONE' },
tables: { test: 'DEFINE TABLE test TYPE NORMAL SCHEMAFULL PERMISSIONS NONE' },
users: {},
}",
)?;
@ -208,7 +208,7 @@ async fn define_statement_table_schemaful() -> Result<(), Error> {
functions: {},
models: {},
params: {},
tables: { test: 'DEFINE TABLE test TYPE ANY SCHEMAFULL PERMISSIONS NONE' },
tables: { test: 'DEFINE TABLE test TYPE NORMAL SCHEMAFULL PERMISSIONS NONE' },
users: {},
}",
);
@ -248,7 +248,7 @@ async fn define_statement_table_foreigntable() -> Result<(), Error> {
models: {},
params: {},
tables: {
test: 'DEFINE TABLE test TYPE ANY SCHEMAFULL PERMISSIONS NONE',
test: 'DEFINE TABLE test TYPE NORMAL SCHEMAFULL PERMISSIONS NONE',
view: 'DEFINE TABLE view TYPE ANY SCHEMALESS AS SELECT count() FROM test GROUP ALL PERMISSIONS NONE',
},
users: {},
@ -280,7 +280,7 @@ async fn define_statement_table_foreigntable() -> Result<(), Error> {
models: {},
params: {},
tables: {
test: 'DEFINE TABLE test TYPE ANY SCHEMAFULL PERMISSIONS NONE',
test: 'DEFINE TABLE test TYPE NORMAL SCHEMAFULL PERMISSIONS NONE',
},
users: {},
}",