From 9d8e9e882defe3c72a50fdd98bf01681a340b361 Mon Sep 17 00:00:00 2001 From: shimizukawa Date: Sun, 16 Oct 2022 20:29:54 +0000 Subject: [PATCH] Drop Django-2.2 support #83 --- django_redshift_backend/__init__.py | 2 +- django_redshift_backend/base.py | 23 ++++++----------------- tests/test_redshift_backend.py | 14 +++----------- 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/django_redshift_backend/__init__.py b/django_redshift_backend/__init__.py index 3a419b8..8abb12d 100644 --- a/django_redshift_backend/__init__.py +++ b/django_redshift_backend/__init__.py @@ -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 diff --git a/django_redshift_backend/base.py b/django_redshift_backend/base.py index 3e18b23..df6cf2b 100644 --- a/django_redshift_backend/base.py +++ b/django_redshift_backend/base.py @@ -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)) @@ -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 @@ -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 = { @@ -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) ) diff --git a/tests/test_redshift_backend.py b/tests/test_redshift_backend.py index 1da0148..3b49adf 100644 --- a/tests/test_redshift_backend.py +++ b/tests/test_redshift_backend.py @@ -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 @@ -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)