Stopped special-casing postgres-specific tests

Refs #23879.
This commit is contained in:
Claude Paroz 2015-04-04 18:10:26 +02:00
parent 6b6d13bf6e
commit 36e90d1f45
12 changed files with 154 additions and 71 deletions

View file

@ -1,11 +1,17 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib.postgres.operations import (
HStoreExtension, UnaccentExtension,
)
from django.db import migrations
try:
from django.contrib.postgres.operations import (
HStoreExtension, UnaccentExtension,
)
except ImportError:
from django.test import mock
HStoreExtension = mock.Mock()
UnaccentExtension = mock.Mock()
class Migration(migrations.Migration):

View file

@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import django.contrib.postgres.fields
import django.contrib.postgres.fields.hstore
from django.db import migrations, models
from ..fields import * # NOQA
class Migration(migrations.Migration):
@ -17,9 +17,10 @@ class Migration(migrations.Migration):
name='CharArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', django.contrib.postgres.fields.ArrayField(models.CharField(max_length=10), size=None)),
('field', ArrayField(models.CharField(max_length=10), size=None)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
@ -27,11 +28,12 @@ class Migration(migrations.Migration):
name='DateTimeArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('datetimes', django.contrib.postgres.fields.ArrayField(models.DateTimeField(), size=None)),
('dates', django.contrib.postgres.fields.ArrayField(models.DateField(), size=None)),
('times', django.contrib.postgres.fields.ArrayField(models.TimeField(), size=None)),
('datetimes', ArrayField(models.DateTimeField(), size=None)),
('dates', ArrayField(models.DateField(), size=None)),
('times', ArrayField(models.TimeField(), size=None)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
@ -39,9 +41,10 @@ class Migration(migrations.Migration):
name='HStoreModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', django.contrib.postgres.fields.hstore.HStoreField(blank=True, null=True)),
('field', HStoreField(blank=True, null=True)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
@ -49,11 +52,12 @@ class Migration(migrations.Migration):
name='OtherTypesArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('ips', django.contrib.postgres.fields.ArrayField(models.GenericIPAddressField(), size=None)),
('uuids', django.contrib.postgres.fields.ArrayField(models.UUIDField(), size=None)),
('decimals', django.contrib.postgres.fields.ArrayField(models.DecimalField(max_digits=5, decimal_places=2), size=None)),
('ips', ArrayField(models.GenericIPAddressField(), size=None)),
('uuids', ArrayField(models.UUIDField(), size=None)),
('decimals', ArrayField(models.DecimalField(max_digits=5, decimal_places=2), size=None)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
@ -61,9 +65,10 @@ class Migration(migrations.Migration):
name='IntegerArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', django.contrib.postgres.fields.ArrayField(models.IntegerField(), size=None)),
('field', ArrayField(models.IntegerField(), size=None)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
@ -71,9 +76,10 @@ class Migration(migrations.Migration):
name='NestedIntegerArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', django.contrib.postgres.fields.ArrayField(django.contrib.postgres.fields.ArrayField(models.IntegerField(), size=None), size=None)),
('field', ArrayField(ArrayField(models.IntegerField(), size=None), size=None)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
@ -81,9 +87,10 @@ class Migration(migrations.Migration):
name='NullableIntegerArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', django.contrib.postgres.fields.ArrayField(models.IntegerField(), size=None, null=True, blank=True)),
('field', ArrayField(models.IntegerField(), size=None, null=True, blank=True)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
@ -130,20 +137,25 @@ class Migration(migrations.Migration):
name='RangesModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('ints', django.contrib.postgres.fields.IntegerRangeField(null=True, blank=True)),
('bigints', django.contrib.postgres.fields.BigIntegerRangeField(null=True, blank=True)),
('floats', django.contrib.postgres.fields.FloatRangeField(null=True, blank=True)),
('timestamps', django.contrib.postgres.fields.DateTimeRangeField(null=True, blank=True)),
('dates', django.contrib.postgres.fields.DateRangeField(null=True, blank=True)),
('ints', IntegerRangeField(null=True, blank=True)),
('bigints', BigIntegerRangeField(null=True, blank=True)),
('floats', FloatRangeField(null=True, blank=True)),
('timestamps', DateTimeRangeField(null=True, blank=True)),
('dates', DateRangeField(null=True, blank=True)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
]
def apply(self, project_state, schema_editor, collect_sql=False):
PG_VERSION = schema_editor.connection.pg_version
if PG_VERSION >= 90200:
self.operations = self.operations + self.pg_92_operations
try:
PG_VERSION = schema_editor.connection.pg_version
except AttributeError:
pass # We are probably not on PostgreSQL
else:
if PG_VERSION >= 90200:
self.operations = self.operations + self.pg_92_operations
return super(Migration, self).apply(project_state, schema_editor, collect_sql)