2014-03-15 01:34:49 +08:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.db import migrations, models
|
2014-03-15 01:34:49 +08:00
|
|
|
|
2015-04-05 00:10:26 +08:00
|
|
|
from ..fields import * # NOQA
|
|
|
|
|
2014-03-15 01:34:49 +08:00
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
|
|
|
('postgres_tests', '0001_setup_extensions'),
|
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.CreateModel(
|
|
|
|
name='CharArrayModel',
|
|
|
|
fields=[
|
|
|
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
2015-04-05 00:10:26 +08:00
|
|
|
('field', ArrayField(models.CharField(max_length=10), size=None)),
|
2014-03-15 01:34:49 +08:00
|
|
|
],
|
|
|
|
options={
|
2015-04-05 00:10:26 +08:00
|
|
|
'required_db_vendor': 'postgresql',
|
2014-03-15 01:34:49 +08:00
|
|
|
},
|
|
|
|
bases=(models.Model,),
|
|
|
|
),
|
|
|
|
migrations.CreateModel(
|
|
|
|
name='DateTimeArrayModel',
|
|
|
|
fields=[
|
|
|
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
2015-04-05 00:10:26 +08:00
|
|
|
('datetimes', ArrayField(models.DateTimeField(), size=None)),
|
|
|
|
('dates', ArrayField(models.DateField(), size=None)),
|
|
|
|
('times', ArrayField(models.TimeField(), size=None)),
|
2014-03-15 01:34:49 +08:00
|
|
|
],
|
|
|
|
options={
|
2015-04-05 00:10:26 +08:00
|
|
|
'required_db_vendor': 'postgresql',
|
2014-03-15 01:34:49 +08:00
|
|
|
},
|
|
|
|
bases=(models.Model,),
|
|
|
|
),
|
|
|
|
migrations.CreateModel(
|
|
|
|
name='HStoreModel',
|
|
|
|
fields=[
|
|
|
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
2015-04-05 00:10:26 +08:00
|
|
|
('field', HStoreField(blank=True, null=True)),
|
2014-03-15 01:34:49 +08:00
|
|
|
],
|
|
|
|
options={
|
2015-04-05 00:10:26 +08:00
|
|
|
'required_db_vendor': 'postgresql',
|
2014-03-15 01:34:49 +08:00
|
|
|
},
|
|
|
|
bases=(models.Model,),
|
|
|
|
),
|
2015-01-11 02:13:28 +08:00
|
|
|
migrations.CreateModel(
|
|
|
|
name='OtherTypesArrayModel',
|
|
|
|
fields=[
|
|
|
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
2015-04-05 00:10:26 +08:00
|
|
|
('ips', ArrayField(models.GenericIPAddressField(), size=None)),
|
|
|
|
('uuids', ArrayField(models.UUIDField(), size=None)),
|
|
|
|
('decimals', ArrayField(models.DecimalField(max_digits=5, decimal_places=2), size=None)),
|
2015-01-11 02:13:28 +08:00
|
|
|
],
|
|
|
|
options={
|
2015-04-05 00:10:26 +08:00
|
|
|
'required_db_vendor': 'postgresql',
|
2015-01-11 02:13:28 +08:00
|
|
|
},
|
|
|
|
bases=(models.Model,),
|
|
|
|
),
|
2014-03-15 01:34:49 +08:00
|
|
|
migrations.CreateModel(
|
|
|
|
name='IntegerArrayModel',
|
|
|
|
fields=[
|
|
|
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
2015-04-05 00:10:26 +08:00
|
|
|
('field', ArrayField(models.IntegerField(), size=None)),
|
2014-03-15 01:34:49 +08:00
|
|
|
],
|
|
|
|
options={
|
2015-04-05 00:10:26 +08:00
|
|
|
'required_db_vendor': 'postgresql',
|
2014-03-15 01:34:49 +08:00
|
|
|
},
|
|
|
|
bases=(models.Model,),
|
|
|
|
),
|
|
|
|
migrations.CreateModel(
|
|
|
|
name='NestedIntegerArrayModel',
|
|
|
|
fields=[
|
|
|
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
2015-04-05 00:10:26 +08:00
|
|
|
('field', ArrayField(ArrayField(models.IntegerField(), size=None), size=None)),
|
2014-03-15 01:34:49 +08:00
|
|
|
],
|
|
|
|
options={
|
2015-04-05 00:10:26 +08:00
|
|
|
'required_db_vendor': 'postgresql',
|
2014-03-15 01:34:49 +08:00
|
|
|
},
|
|
|
|
bases=(models.Model,),
|
|
|
|
),
|
|
|
|
migrations.CreateModel(
|
|
|
|
name='NullableIntegerArrayModel',
|
|
|
|
fields=[
|
|
|
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
2015-04-05 00:10:26 +08:00
|
|
|
('field', ArrayField(models.IntegerField(), size=None, null=True, blank=True)),
|
2014-03-15 01:34:49 +08:00
|
|
|
],
|
|
|
|
options={
|
2015-04-05 00:10:26 +08:00
|
|
|
'required_db_vendor': 'postgresql',
|
2014-03-15 01:34:49 +08:00
|
|
|
},
|
|
|
|
bases=(models.Model,),
|
|
|
|
),
|
2014-09-06 04:53:11 +08:00
|
|
|
migrations.CreateModel(
|
|
|
|
name='CharFieldModel',
|
|
|
|
fields=[
|
|
|
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
|
|
|
('field', models.CharField(max_length=16)),
|
|
|
|
],
|
|
|
|
options=None,
|
|
|
|
bases=None,
|
|
|
|
),
|
|
|
|
migrations.CreateModel(
|
|
|
|
name='TextFieldModel',
|
|
|
|
fields=[
|
|
|
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
|
|
|
('field', models.TextField()),
|
|
|
|
],
|
|
|
|
options=None,
|
|
|
|
bases=None,
|
|
|
|
),
|
2015-02-08 23:21:48 +08:00
|
|
|
migrations.CreateModel(
|
|
|
|
name='AggregateTestModel',
|
|
|
|
fields=[
|
|
|
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
|
|
|
('boolean_field', models.NullBooleanField()),
|
|
|
|
('char_field', models.CharField(max_length=30, blank=True)),
|
|
|
|
('integer_field', models.IntegerField(null=True)),
|
|
|
|
]
|
|
|
|
),
|
|
|
|
migrations.CreateModel(
|
|
|
|
name='StatTestModel',
|
|
|
|
fields=[
|
|
|
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
|
|
|
('int1', models.IntegerField()),
|
|
|
|
('int2', models.IntegerField()),
|
|
|
|
('related_field', models.ForeignKey('postgres_tests.AggregateTestModel', null=True)),
|
|
|
|
]
|
|
|
|
),
|
2014-03-15 01:34:49 +08:00
|
|
|
]
|
2015-01-11 00:14:20 +08:00
|
|
|
|
|
|
|
pg_92_operations = [
|
|
|
|
migrations.CreateModel(
|
|
|
|
name='RangesModel',
|
|
|
|
fields=[
|
|
|
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
2015-04-05 00:10:26 +08:00
|
|
|
('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)),
|
2015-01-11 00:14:20 +08:00
|
|
|
],
|
|
|
|
options={
|
2015-04-05 00:10:26 +08:00
|
|
|
'required_db_vendor': 'postgresql',
|
2015-01-11 00:14:20 +08:00
|
|
|
},
|
|
|
|
bases=(models.Model,),
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
2015-05-31 05:13:58 +08:00
|
|
|
pg_94_operations = [
|
|
|
|
migrations.CreateModel(
|
|
|
|
name='JSONModel',
|
|
|
|
fields=[
|
|
|
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
|
|
|
('field', JSONField(null=True, blank=True)),
|
|
|
|
],
|
|
|
|
options={
|
|
|
|
},
|
|
|
|
bases=(models.Model,),
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
2015-01-11 00:14:20 +08:00
|
|
|
def apply(self, project_state, schema_editor, collect_sql=False):
|
2015-04-05 00:10:26 +08:00
|
|
|
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
|
2015-05-31 05:13:58 +08:00
|
|
|
if PG_VERSION >= 90400:
|
|
|
|
self.operations = self.operations + self.pg_94_operations
|
2015-01-11 00:14:20 +08:00
|
|
|
return super(Migration, self).apply(project_state, schema_editor, collect_sql)
|