Skip to content

Commit 1bb8ec7

Browse files
authored
fix(rules): require concurrent index creation (#157)
We weren't checking what type of drop was happening, so any drop stmt that wasn't marked concurrent was causing an error. #151 #152 #156
1 parent efa9027 commit 1bb8ec7

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

linter/src/rules/require_concurrent_index_creation.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::rules::utils::tables_created_in_transaction;
22
use crate::violations::{RuleViolation, RuleViolationKind};
3-
use squawk_parser::ast::{RelationKind, RootStmt, Stmt};
3+
use squawk_parser::ast::{ObjectType, RelationKind, RootStmt, Stmt};
44

55
#[must_use]
66
pub fn require_concurrent_index_creation(tree: &[RootStmt]) -> Vec<RuleViolation> {
@@ -19,11 +19,13 @@ pub fn require_concurrent_index_creation(tree: &[RootStmt]) -> Vec<RuleViolation
1919
));
2020
}
2121
}
22-
Stmt::DropStmt(stmt) if !stmt.concurrent => errs.push(RuleViolation::new(
23-
RuleViolationKind::RequireConcurrentIndexCreation,
24-
raw_stmt.into(),
25-
None,
26-
)),
22+
Stmt::DropStmt(stmt) if !stmt.concurrent && stmt.remove_type == ObjectType::Index => {
23+
errs.push(RuleViolation::new(
24+
RuleViolationKind::RequireConcurrentIndexCreation,
25+
raw_stmt.into(),
26+
None,
27+
))
28+
}
2729
_ => continue,
2830
}
2931
}
@@ -76,4 +78,28 @@ mod test_rules {
7678
"#;
7779
assert_eq!(check_sql(ok_sql, &[]), Ok(vec![]));
7880
}
81+
82+
#[test]
83+
fn regression_false_positive_drop_type() {
84+
let sql = r#"
85+
DROP TYPE IF EXISTS foo;
86+
"#;
87+
assert_eq!(check_sql(sql, &[]), Ok(vec![]));
88+
}
89+
90+
#[test]
91+
fn regression_false_positive_drop_table() {
92+
let sql = r#"
93+
DROP TABLE IF EXISTS some_table;
94+
"#;
95+
assert_eq!(check_sql(sql, &[]), Ok(vec![]));
96+
}
97+
98+
#[test]
99+
fn regression_false_positive_drop_trigger() {
100+
let sql = r#"
101+
DROP TRIGGER IF EXISTS trigger on foo_table;
102+
"#;
103+
assert_eq!(check_sql(sql, &[]), Ok(vec![]));
104+
}
79105
}

0 commit comments

Comments
 (0)