Skip to content

NOT NULL in triggers/functions #263

@BranislavBajuzik

Description

@BranislavBajuzik

Hello.

I am using this tool to lint my Postgres migrations (definitely prevented several headaches on deploy) and I found a false-positive:

BEGIN;
-- Create trigger api_user_update on model user
            CREATE OR REPLACE FUNCTION "public"._pgtrigger_should_ignore(
                trigger_name NAME
            )
            RETURNS BOOLEAN AS $$
                DECLARE
                    _pgtrigger_ignore TEXT[];
                BEGIN
                    IF _pgtrigger_ignore IS NOT NULL THEN
                        SELECT trigger_name = ANY(_pgtrigger_ignore)
                 -- And so on
COMMIT;

The migration/sql is courtesy of django-pgtrigger.

This gets flagged because of the if statement, which I think should not trip up the detection. It gets flagged here:

re.search("(?<!DROP )NOT NULL", sql)

Some of my hand-written migrations also get flagged for this reason.

If I also may, I suggest that the .startswith() checks should be .strip().lower().startswith() to deal with possible future regressions because of indented/hand-written migrations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions