Skip to content

Commit

Permalink
Don't consider partial unique index creation as making a column not n…
Browse files Browse the repository at this point in the history
…ullable.
  • Loading branch information
devend711 authored and David-Wobrock committed Mar 30, 2024
1 parent b15924c commit a230681
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Feature:

Bug:
- Don't detect 'IS NOT NULL' as backward incompatible changes (issue #263)
- Don't consider UNIQUE INDEX creation as making a column not nullable

Miscellaneous:

Expand Down
4 changes: 3 additions & 1 deletion src/django_migration_linter/sql_analyser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def has_not_null_column(sql_statements: list[str], **kwargs) -> bool:

for sql in sql_statements:
if re.search("(?<!DROP )(?<!IS )NOT NULL", sql) and not (
sql.startswith("CREATE TABLE") or sql.startswith("CREATE INDEX")
sql.startswith("CREATE TABLE")
or sql.startswith("CREATE INDEX")
or sql.startswith("CREATE UNIQUE INDEX")
):
not_null_column = True
if re.search("DEFAULT.*NOT NULL", sql):
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_sql_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ def test_create_index_concurrently_where(self):
sql = 'CREATE INDEX CONCURRENTLY "index_name" ON "table_name" ("a_column") WHERE ("some_column" IS NOT NULL);'
self.assertValidSql(sql)

def test_create_unique_index_concurrently_where(self):
sql = 'CREATE UNIQUE INDEX CONCURRENTLY "index_name" ON "table_name" ("a_column") WHERE ("some_column" IS NOT NULL);'
self.assertBackwardIncompatibleSql(sql, "ADD_UNIQUE")

def test_drop_index_non_concurrently(self):
sql = "DROP INDEX ON films"
self.assertWarningSql(sql)
Expand Down

0 comments on commit a230681

Please sign in to comment.