Skip to content

Commit

Permalink
Add Django-5.0 support #143; fix features
Browse files Browse the repository at this point in the history
  • Loading branch information
shimizukawa committed Sep 14, 2024
1 parent 705853d commit f038433
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 5 additions & 4 deletions django_redshift_backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ class DatabaseFeatures(BasePGDatabaseFeatures):
allows_group_by_select_index = True # since django-4.2
# since django-4.2. I don't know the Redshift supports comments or not.
supports_comments = False
# since django-5.0. I don't know the Redshift supports default expression
supports_default_keyword_in_insert = True # TODO: Add UnitTest https://docs.djangoproject.com/en/5.0/releases/5.0/#database-computed-default-values
supports_default_keyword_in_bulk_insert = True # TODO: Add UnitTest https://docs.djangoproject.com/en/5.0/releases/5.0/#database-computed-default-values
supports_nulls_distinct_unique_constraints = False # TODO: Add UnitTest https://docs.djangoproject.com/en/5.0/ref/models/constraints/#nulls-distinct
# django-redshift-backend does not support dj50 features due to dj40 codebase.
# https://docs.djangoproject.com/en/5.0/releases/5.0/
supports_default_keyword_in_insert = False
supports_default_keyword_in_bulk_insert = False
supports_nulls_distinct_unique_constraints = False

# If support atomic for ddl, we should implement non-atomic migration for on rename and change type(size)
# refs django-redshift-backend #96
Expand Down
21 changes: 21 additions & 0 deletions tests/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,27 @@ def test_add_notnull_with_default(self):
'''ALTER TABLE "test_pony" ADD COLUMN "name" varchar(10) DEFAULT '' NOT NULL;''',
], sqls)

@pytest.mark.skip('django-redshift-backend does not support in-database defaults')
@postgres_fixture()
def test_add_db_default(self):
from django.db.models.functions import Now

new_state = self.set_up_test_model('test')
operations = [
migrations.AddField(
model_name='Pony',
name='birthday',
field=models.DateTimeField(null=False, db_default=Now()),
),
]

with self.collect_sql() as sqls:
self.apply_operations('test', new_state, operations)

self.assertEqual([
'''ALTER TABLE "test_pony" ADD COLUMN "birthday" timestamp with time zone DEFAULT now() NOT NULL;''',
], sqls)

@postgres_fixture()
def test_add_binary(self):
from django_redshift_backend.base import DatabaseWrapper, _remove_length_from_type
Expand Down

0 comments on commit f038433

Please sign in to comment.