Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions crates/squawk_linter/src/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.",
Expand Down
28 changes: 0 additions & 28 deletions crates/squawk_linter/src/rules/prefer_robust_stmts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
let mut inside_transaction = ctx.settings.assume_in_transaction;
let mut constraint_names: HashMap<Identifier, Constraint> = 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,
Expand Down Expand Up @@ -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#"
Expand Down
Loading