Skip to content

Commit

Permalink
fix: prefer-robust-stmts w/ rls (#367)
Browse files Browse the repository at this point in the history
fixes #308


not sure if we should be checking for the `if exists` or what, but better than erroring for now

you can call disable / enable multiple times and Postgres won't error
  • Loading branch information
sbdchd authored Aug 3, 2024
1 parent ca1f346 commit 2993811
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
36 changes: 36 additions & 0 deletions linter/src/rules/prefer_robust_stmts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ pub fn prefer_robust_stmts(
}
}

if cmd.subtype == AlterTableType::EnableRowSecurity
|| cmd.subtype == AlterTableType::DisableRowSecurity
{
continue;
}

if let Some(AlterTableDef::Constraint(constraint)) = &cmd.def {
if let Some(constraint_name) = &constraint.conname {
if let Some(constraint) = constraint_names.get_mut(constraint_name) {
Expand Down Expand Up @@ -288,6 +294,36 @@ DROP TYPE foo;
fn test_create_index_concurrently_unnamed() {
let bad_sql = r#"
CREATE INDEX CONCURRENTLY ON "table_name" ("field_name");
"#;

assert_debug_snapshot!(lint_sql(bad_sql));
}

#[test]
fn enable_row_level_security() {
let bad_sql = r#"
CREATE TABLE IF NOT EXISTS test();
ALTER TABLE IF EXISTS test ENABLE ROW LEVEL SECURITY;
"#;

assert_debug_snapshot!(lint_sql(bad_sql));
}

#[test]
fn enable_row_level_security_without_exists_check() {
let bad_sql = r#"
CREATE TABLE IF NOT EXISTS test();
ALTER TABLE test ENABLE ROW LEVEL SECURITY;
"#;

assert_debug_snapshot!(lint_sql(bad_sql));
}

#[test]
fn disable_row_level_security() {
let bad_sql = r#"
CREATE TABLE IF NOT EXISTS test();
ALTER TABLE IF EXISTS test DISABLE ROW LEVEL SECURITY;
"#;

assert_debug_snapshot!(lint_sql(bad_sql));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: linter/src/rules/prefer_robust_stmts.rs
expression: lint_sql(bad_sql)
---
Ok(
[],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: linter/src/rules/prefer_robust_stmts.rs
expression: lint_sql(bad_sql)
---
Ok(
[],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: linter/src/rules/prefer_robust_stmts.rs
expression: lint_sql(bad_sql)
---
Ok(
[],
)

0 comments on commit 2993811

Please sign in to comment.