diff --git a/crates/squawk_linter/src/rules/adding_not_null_field.rs b/crates/squawk_linter/src/rules/adding_not_null_field.rs index fb5ddf5c..c3a4e2a9 100644 --- a/crates/squawk_linter/src/rules/adding_not_null_field.rs +++ b/crates/squawk_linter/src/rules/adding_not_null_field.rs @@ -3,12 +3,9 @@ use squawk_syntax::{ Parse, SourceFile, }; -use crate::{Linter, Rule, Version, Violation}; +use crate::{Linter, Rule, Violation}; pub(crate) fn adding_not_null_field(ctx: &mut Linter, parse: &Parse) { - if ctx.settings.pg_version >= Version::new(11, 0, 0) { - return; - } let file = parse.tree(); for stmt in file.stmts() { if let ast::Stmt::AlterTable(alter_table) = stmt { @@ -38,7 +35,7 @@ pub(crate) fn adding_not_null_field(ctx: &mut Linter, parse: &Parse) mod test { use insta::assert_debug_snapshot; - use crate::{Linter, Rule, Version}; + use crate::{Linter, Rule}; #[test] fn set_not_null() { @@ -47,7 +44,6 @@ ALTER TABLE "core_recipe" ALTER COLUMN "foo" SET NOT NULL; "#; let file = squawk_syntax::SourceFile::parse(sql); let mut linter = Linter::from([Rule::AddingNotNullableField]); - linter.settings.pg_version = Version::new(10, 0, 0); let errors = linter.lint(file, sql); assert!(!errors.is_empty()); assert_debug_snapshot!(errors); @@ -96,4 +92,20 @@ COMMIT; let errors = linter.lint(file, sql); assert!(errors.is_empty()); } + + #[test] + fn regression_gh_issue_519() { + let sql = r#" +BEGIN; +-- Running upgrade a -> b +ALTER TABLE my_table ALTER COLUMN my_column SET NOT NULL; +UPDATE alembic_version SET version_num='b' WHERE alembic_version.version_num = 'a'; +COMMIT; + "#; + let file = squawk_syntax::SourceFile::parse(sql); + let mut linter = Linter::from([Rule::AddingNotNullableField]); + let errors = linter.lint(file, sql); + assert!(!errors.is_empty()); + assert_debug_snapshot!(errors); + } } diff --git a/crates/squawk_linter/src/rules/snapshots/squawk_linter__rules__adding_not_null_field__test__regression_gh_issue_519.snap b/crates/squawk_linter/src/rules/snapshots/squawk_linter__rules__adding_not_null_field__test__regression_gh_issue_519.snap new file mode 100644 index 00000000..54cbadd9 --- /dev/null +++ b/crates/squawk_linter/src/rules/snapshots/squawk_linter__rules__adding_not_null_field__test__regression_gh_issue_519.snap @@ -0,0 +1,14 @@ +--- +source: crates/squawk_linter/src/rules/adding_not_null_field.rs +expression: errors +--- +[ + Violation { + code: AddingNotNullableField, + message: "Setting a column `NOT NULL` blocks reads while the table is scanned.", + text_range: 78..90, + help: Some( + "Make the field nullable and use a `CHECK` constraint instead.", + ), + }, +]