squawk 2.48.0

Linter for Postgresql focused on database migrations.
---
source: crates/squawk/src/reporter.rs
expression: "check_sql(sql, filename, &[], None, false)"
---
CheckReport {
    filename: "main.sql",
    sql: "\n\n   ALTER TABLE \"core_recipe\" ADD COLUMN \"foo\" integer NOT NULL;\nALTER TABLE \"core_foo\" ADD COLUMN \"bar\" integer NOT NULL;\nSELECT 1;\n",
    violations: [
        ReportViolation {
            file: "main.sql",
            line: 2,
            column: 3,
            range: 5..64,
            level: Warning,
            message: "Missing `set lock_timeout` before potentially slow operations",
            help: Some(
                "Configure a `lock_timeout` before this statement.",
            ),
            rule_name: "require-timeout-settings",
            column_end: 62,
            line_end: 2,
            fix: Some(
                Fix {
                    title: "Add lock timeout",
                    edits: [
                        Edit {
                            text_range: 5..5,
                            text: Some(
                                "set lock_timeout = '1s';\n",
                            ),
                        },
                    ],
                },
            ),
        },
        ReportViolation {
            file: "main.sql",
            line: 2,
            column: 3,
            range: 5..64,
            level: Warning,
            message: "Missing `set statement_timeout` before potentially slow operations",
            help: Some(
                "Configure a `statement_timeout` before this statement",
            ),
            rule_name: "require-timeout-settings",
            column_end: 62,
            line_end: 2,
            fix: Some(
                Fix {
                    title: "Add statement timeout",
                    edits: [
                        Edit {
                            text_range: 5..5,
                            text: Some(
                                "set statement_timeout = '5s';\n",
                            ),
                        },
                    ],
                },
            ),
        },
        ReportViolation {
            file: "main.sql",
            line: 2,
            column: 29,
            range: 31..64,
            level: Warning,
            message: "Adding a new column that is `NOT NULL` and has no default value to an existing table effectively makes it required.",
            help: Some(
                "Make the field nullable or add a non-VOLATILE DEFAULT",
            ),
            rule_name: "adding-required-field",
            column_end: 62,
            line_end: 2,
            fix: None,
        },
        ReportViolation {
            file: "main.sql",
            line: 2,
            column: 29,
            range: 31..64,
            level: Warning,
            message: "Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through.",
            help: None,
            rule_name: "prefer-robust-stmts",
            column_end: 62,
            line_end: 2,
            fix: Some(
                Fix {
                    title: "Insert `if not exists`",
                    edits: [
                        Edit {
                            text_range: 41..41,
                            text: Some(
                                " if not exists",
                            ),
                        },
                    ],
                },
            ),
        },
        ReportViolation {
            file: "main.sql",
            line: 2,
            column: 46,
            range: 48..55,
            level: Warning,
            message: "Using 32-bit integer fields can result in hitting the max `int` limit.",
            help: Some(
                "Use 64-bit integer values instead to prevent hitting this limit.",
            ),
            rule_name: "prefer-bigint-over-int",
            column_end: 53,
            line_end: 2,
            fix: Some(
                Fix {
                    title: "Replace with a 64-bit integer type: `bigint`",
                    edits: [
                        Edit {
                            text_range: 48..55,
                            text: Some(
                                "bigint",
                            ),
                        },
                    ],
                },
            ),
        },
        ReportViolation {
            file: "main.sql",
            line: 3,
            column: 23,
            range: 89..122,
            level: Warning,
            message: "Adding a new column that is `NOT NULL` and has no default value to an existing table effectively makes it required.",
            help: Some(
                "Make the field nullable or add a non-VOLATILE DEFAULT",
            ),
            rule_name: "adding-required-field",
            column_end: 56,
            line_end: 3,
            fix: None,
        },
        ReportViolation {
            file: "main.sql",
            line: 3,
            column: 23,
            range: 89..122,
            level: Warning,
            message: "Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through.",
            help: None,
            rule_name: "prefer-robust-stmts",
            column_end: 56,
            line_end: 3,
            fix: Some(
                Fix {
                    title: "Insert `if not exists`",
                    edits: [
                        Edit {
                            text_range: 99..99,
                            text: Some(
                                " if not exists",
                            ),
                        },
                    ],
                },
            ),
        },
        ReportViolation {
            file: "main.sql",
            line: 3,
            column: 40,
            range: 106..113,
            level: Warning,
            message: "Using 32-bit integer fields can result in hitting the max `int` limit.",
            help: Some(
                "Use 64-bit integer values instead to prevent hitting this limit.",
            ),
            rule_name: "prefer-bigint-over-int",
            column_end: 47,
            line_end: 3,
            fix: Some(
                Fix {
                    title: "Replace with a 64-bit integer type: `bigint`",
                    edits: [
                        Edit {
                            text_range: 106..113,
                            text: Some(
                                "bigint",
                            ),
                        },
                    ],
                },
            ),
        },
    ],
}