from __future__ import unicode_literals

import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('munigeo', '0003_add_modified_time_to_address_and_street'),
    ]

    operations = [
        migrations.CreateModel(
            name='Building',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('origin_id', models.CharField(db_index=True, max_length=40)),
                ('geometry', django.contrib.gis.db.models.fields.MultiPolygonField(srid=4326)),
                ('modified_at', models.DateTimeField(auto_now=True, help_text='Time when the information was last changed')),
                ('addresses', models.ManyToManyField(blank=True, to='munigeo.Address')),
                ('municipality', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='munigeo.Municipality')),
            ],
            options={
                'ordering': ['municipality', 'origin_id'],
            },
        ),
    ]

from __future__ import unicode_literals

import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.db.models.deletion

from munigeo.utils import get_default_srid
DEFAULT_SRID = get_default_srid()


class Migration(migrations.Migration):

    dependencies = [
        ('munigeo', '0003_add_modified_time_to_address_and_street'),
    ]

    operations = [
        migrations.CreateModel(
            name='Building',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('origin_id', models.CharField(db_index=True, max_length=40)),
                ('geometry', django.contrib.gis.db.models.fields.MultiPolygonField(srid=DEFAULT_SRID)),
                ('modified_at', models.DateTimeField(auto_now=True, help_text='Time when the information was last changed')),
                ('addresses', models.ManyToManyField(blank=True, to='munigeo.Address')),
                ('municipality', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='munigeo.Municipality')),
            ],
            options={
                'ordering': ['municipality', 'origin_id'],
            },
        ),
    ]

Fix building migration SRID logic
Fix building migration SRID logic

Hardcoding the SRID in the migration could result in a mismatch
between the model srid and the migration srid.

  from __future__ import unicode_literals
  
  import django.contrib.gis.db.models.fields
  from django.db import migrations, models
  import django.db.models.deletion
+ 
+ from munigeo.utils import get_default_srid
+ DEFAULT_SRID = get_default_srid()
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('munigeo', '0003_add_modified_time_to_address_and_street'),
      ]
  
      operations = [
          migrations.CreateModel(
              name='Building',
              fields=[
                  ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                  ('origin_id', models.CharField(db_index=True, max_length=40)),
-                 ('geometry', django.contrib.gis.db.models.fields.MultiPolygonField(srid=4326)),
+                 ('geometry', django.contrib.gis.db.models.fields.MultiPolygonField(srid=DEFAULT_SRID)),
                  ('modified_at', models.DateTimeField(auto_now=True, help_text='Time when the information was last changed')),
                  ('addresses', models.ManyToManyField(blank=True, to='munigeo.Address')),
                  ('municipality', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='munigeo.Municipality')),
              ],
              options={
                  'ordering': ['municipality', 'origin_id'],
              },
          ),
      ]
  
Fix building migration SRID logic
## Code Before:
from __future__ import unicode_literals

import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('munigeo', '0003_add_modified_time_to_address_and_street'),
    ]

    operations = [
        migrations.CreateModel(
            name='Building',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('origin_id', models.CharField(db_index=True, max_length=40)),
                ('geometry', django.contrib.gis.db.models.fields.MultiPolygonField(srid=4326)),
                ('modified_at', models.DateTimeField(auto_now=True, help_text='Time when the information was last changed')),
                ('addresses', models.ManyToManyField(blank=True, to='munigeo.Address')),
                ('municipality', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='munigeo.Municipality')),
            ],
            options={
                'ordering': ['municipality', 'origin_id'],
            },
        ),
    ]

## Instruction:
Fix building migration SRID logic
## Code After:
from __future__ import unicode_literals

import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.db.models.deletion

from munigeo.utils import get_default_srid
DEFAULT_SRID = get_default_srid()


class Migration(migrations.Migration):

    dependencies = [
        ('munigeo', '0003_add_modified_time_to_address_and_street'),
    ]

    operations = [
        migrations.CreateModel(
            name='Building',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('origin_id', models.CharField(db_index=True, max_length=40)),
                ('geometry', django.contrib.gis.db.models.fields.MultiPolygonField(srid=DEFAULT_SRID)),
                ('modified_at', models.DateTimeField(auto_now=True, help_text='Time when the information was last changed')),
                ('addresses', models.ManyToManyField(blank=True, to='munigeo.Address')),
                ('municipality', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='munigeo.Municipality')),
            ],
            options={
                'ordering': ['municipality', 'origin_id'],
            },
        ),
    ]
