diff --git a/crates/squawk_linter/src/ignore.rs b/crates/squawk_linter/src/ignore.rs index 2d97dd22..962bcc1f 100644 --- a/crates/squawk_linter/src/ignore.rs +++ b/crates/squawk_linter/src/ignore.rs @@ -301,6 +301,25 @@ create table users ( }, ), }, + Violation { + code: PreferRobustStmts, + message: "Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through.", + text_range: 14..31, + help: None, + fix: Some( + Fix { + title: "Insert `if not exists`", + edits: [ + Edit { + text_range: 24..24, + text: Some( + " if not exists", + ), + }, + ], + }, + ), + }, Violation { code: BanCharField, message: "Using `character` is likely a mistake and should almost always be replaced by `text` or `varchar`.", diff --git a/crates/squawk_linter/src/rules/prefer_robust_stmts.rs b/crates/squawk_linter/src/rules/prefer_robust_stmts.rs index 11081130..7233af00 100644 --- a/crates/squawk_linter/src/rules/prefer_robust_stmts.rs +++ b/crates/squawk_linter/src/rules/prefer_robust_stmts.rs @@ -19,18 +19,6 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse) { let mut inside_transaction = ctx.settings.assume_in_transaction; let mut constraint_names: HashMap = HashMap::new(); - let mut total_stmts = 0; - for _ in file.stmts() { - total_stmts += 1; - if total_stmts > 1 { - break; - } - } - if total_stmts <= 1 { - // single stmts are fine - return; - } - enum ActionErrorMessage { IfExists, IfNotExists, @@ -512,22 +500,6 @@ CREATE TABLE "core_bar" ( ); } - #[test] - fn ignore_single_stmts_ok() { - // we don't include a placeholder stmt because we're actually checking - // for the single stmt behavior here - let sql = r#" -CREATE INDEX CONCURRENTLY ON "table_name" ("field_name"); - "#; - lint_ok_with( - sql, - LinterSettings { - assume_in_transaction: true, - ..Default::default() - }, - ); - } - #[test] fn create_index_concurrently_without_name_ok() { let sql = r#"