Skip to content

Commit

Permalink
fix deferred sql errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tbicr committed Feb 11, 2024
1 parent cbfad83 commit 5fddddf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# django-pg-zero-downtime-migrations changelog

## 0.14
- fix deferred sql errors
- drop postgres 11 support
- mark `migrate_isnotnull_check_constraints` command deprecated

Expand Down
10 changes: 6 additions & 4 deletions django_zero_downtime_migrations/backends/postgres/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def __init__(self, connection, collect_sql=False, atomic=True):
self.FLEXIBLE_STATEMENT_TIMEOUT = getattr(
settings, "ZERO_DOWNTIME_MIGRATIONS_FLEXIBLE_STATEMENT_TIMEOUT", False)
self.RAISE_FOR_UNSAFE = getattr(settings, "ZERO_DOWNTIME_MIGRATIONS_RAISE_FOR_UNSAFE", False)
self.DEFERRED_SQL = getattr(settings, "ZERO_DOWNTIME_DEFERRED_SQL", True)

def execute(self, sql, params=()):
if sql is DUMMY_SQL:
Expand Down Expand Up @@ -296,12 +297,13 @@ def _set_operation_timeout(self, statement_timeout=None, lock_timeout=None):
self.execute(self.sql_set_lock_timeout % {"lock_timeout": previous_lock_timeout})

def _flush_deferred_sql(self):
"""As some alternative sql use deferred sql and deferred sql run after all operations in miration module
"""As some alternative sql use deferred sql and deferred sql run after all operations in migration module
so good idea to run deferred sql as soon as possible to provide similar as possible state
between operations in migration module."""
for sql in self.deferred_sql:
self.execute(sql)
self.deferred_sql.clear()
if not self.DEFERRED_SQL:
for sql in self.deferred_sql:
self.execute(sql)
self.deferred_sql.clear()

def create_model(self, model):
super().create_model(model)
Expand Down
9 changes: 9 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

MIGRATION_MODULES = {
'admin': None,
'auth': None,
'contenttypes': None,
'sessions': None,
'messages': None,
'staticfiles': None,
}

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
Expand Down

0 comments on commit 5fddddf

Please sign in to comment.