Skip to content

Commit

Permalink
Drop Django-2.2 support #83
Browse files Browse the repository at this point in the history
  • Loading branch information
shimizukawa committed Oct 16, 2022
1 parent e61e8f3 commit 9d8e9e8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
2 changes: 1 addition & 1 deletion django_redshift_backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
except PackageNotFoundError:
# package is not installed
pass
except ImportError: # py36, py37
except ImportError: # py37
from pkg_resources import get_distribution, DistributionNotFound
try:
__version__ = get_distribution(__name__).version
Expand Down
23 changes: 6 additions & 17 deletions django_redshift_backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ class DatabaseSchemaEditor(BasePGDatabaseSchemaEditor):
sql_create_table = "CREATE TABLE %(table)s (%(definition)s) %(options)s"
sql_delete_fk = "ALTER TABLE %(table)s DROP CONSTRAINT %(name)s"

if django.VERSION < (3,):
# to remove "USING %(column)s::%(type)s"
sql_alter_column_type = "ALTER COLUMN %(column)s TYPE %(type)s"

@property
def multiply_varchar_length(self):
return int(getattr(settings, "REDSHIFT_VARCHAR_LENGTH_MULTIPLIER", 1))
Expand Down Expand Up @@ -878,7 +874,7 @@ def _create_unique_sql(
self, model, fields, name=None, condition=None, deferrable=None,
include=None, opclasses=None, expressions=None,
):
if django.VERSION >= (4,):
if django.VERSION >= (4,): # dj40 support
return super()._create_unique_sql(
model, fields, name=name, condition=condition, deferrable=deferrable,
include=include, opclasses=opclasses, expressions=expressions
Expand All @@ -892,13 +888,8 @@ def _create_unique_sql(
model, columns, name=name, condition=condition, deferrable=deferrable,
include=include, opclasses=opclasses,
)
else: # dj32, dj22 support
columns = [
field.column if hasattr(field, 'column') else field
for field in fields
]
return super()._create_unique_sql(
model, columns, name=name, condition=condition)
else: # dj22 or earlier are not supported
raise NotImplementedError


redshift_data_types = {
Expand Down Expand Up @@ -947,15 +938,13 @@ def get_table_description(self, cursor, table_name):
# field_map = {line[0]: line[1:] for line in cursor.fetchall()}
field_map = {}
for column_name, is_nullable, column_default in cursor.fetchall():
_field_map = {
field_map[column_name] = {
'null_ok': is_nullable,
'default': column_default,
}
if django.VERSION >= (3, 2):
# Redshift doesn't support user-defined collation
# https://docs.aws.amazon.com/redshift/latest/dg/c_collation_sequences.html
_field_map['collation'] = None
field_map[column_name] = _field_map
'collation': None,
}
cursor.execute(
"SELECT * FROM %s LIMIT 1" % self.connection.ops.quote_name(table_name)
)
Expand Down
14 changes: 3 additions & 11 deletions tests/test_redshift_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import unittest

import django
from django.db import connections
from django.db.utils import NotSupportedError
from django.core.management.color import no_style
Expand Down Expand Up @@ -158,16 +157,9 @@ def test_create_table_meta_keys(self):
reason='to run, TEST_WITH_POSTGRES=1 tox')
def test_sqlmigrate(self):
from django.db import connection

if django.VERSION < (3, 0): # for dj22
from django.db.migrations.executor import MigrationExecutor
executor = MigrationExecutor(connection)
loader = executor.loader
collect_sql = executor.collect_sql
else:
from django.db.migrations.loader import MigrationLoader
loader = MigrationLoader(connection)
collect_sql = loader.collect_sql
from django.db.migrations.loader import MigrationLoader
loader = MigrationLoader(connection)
collect_sql = loader.collect_sql

app_label, migration_name = 'testapp', '0001'
migration = loader.get_migration_by_prefix(app_label, migration_name)
Expand Down

0 comments on commit 9d8e9e8

Please sign in to comment.