Ticket #22481: 22481-1.diff

File 22481-1.diff, 3.4 KB (added by Claude Paroz, 11 years ago)
  • django/contrib/gis/db/backends/postgis/schema.py

    diff --git a/django/contrib/gis/db/backends/postgis/schema.py b/django/contrib/gis/db/backends/postgis/schema.py
    index 7d4c42f..1ef059f 100644
    a b class PostGISSchemaEditor(DatabaseSchemaEditor):  
    77    geom_index_ops_nd = 'GIST_GEOMETRY_OPS_ND'
    88
    99    sql_add_geometry_column = "SELECT AddGeometryColumn(%(table)s, %(column)s, %(srid)s, %(geom_type)s, %(dim)s)"
     10    sql_drop_geometry_column = "SELECT DropGeometryColumn(%(table)s, %(column)s)"
    1011    sql_alter_geometry_column_not_null = "ALTER TABLE %(table)s ALTER COLUMN %(column)s SET NOT NULL"
    1112    sql_add_spatial_index = "CREATE INDEX %(index)s ON %(table)s USING %(index_type)s (%(column)s %(ops)s)"
    1213
    class PostGISSchemaEditor(DatabaseSchemaEditor):  
    7071                }
    7172            )
    7273        return column_sql
     74
     75    def remove_field(self, model, field):
     76        from django.contrib.gis.db.models.fields import GeometryField
     77        if not isinstance(field, GeometryField) or self.connection.ops.spatial_version < (2, 0):
     78            super(PostGISSchemaEditor, self).remove_field(model, field)
     79
     80        self.execute(
     81            self.sql_drop_geometry_column % {
     82                "table": self.geo_quote_name(model._meta.db_table),
     83                "column": self.geo_quote_name(field.column),
     84            }
     85        )
  • django/contrib/gis/tests/gis_migrations/migrations/0002_add_linestring_field.py

    diff --git a/django/contrib/gis/tests/gis_migrations/migrations/0002_add_linestring_field.py b/django/contrib/gis/tests/gis_migrations/migrations/0002_add_linestring_field.py
    index 4d7a33a..62803a0 100644
    a b class Migration(migrations.Migration):  
    1818            field=django.contrib.gis.db.models.fields.LineStringField(srid=4326, null=True, blank=True),
    1919            preserve_default=True,
    2020        ),
     21        migrations.RemoveField('Neighborhood', 'geom'),
    2122    ]
  • django/contrib/gis/tests/gis_migrations/test_commands.py

    diff --git a/django/contrib/gis/tests/gis_migrations/test_commands.py b/django/contrib/gis/tests/gis_migrations/test_commands.py
    index 4766bfc..35b42ec 100644
    a b class MigrateTests(TransactionTestCase):  
    3030        field_names = [info.name for info in self.get_table_description(table)]
    3131        self.assertIn(field, field_names)
    3232
     33    def assertFieldNotExists(self, table, field):
     34        field_names = [info.name for info in self.get_table_description(table)]
     35        self.assertNotIn(field, field_names)
     36
    3337    @skipUnless(HAS_SPATIAL_DB, "Spatial db is required.")
    3438    @override_system_checks([])
    3539    @override_settings(MIGRATION_MODULES={"gis": "django.contrib.gis.tests.gis_migrations.migrations"})
    class MigrateTests(TransactionTestCase):  
    4953        self.assertTableExists("gis_household")
    5054        # Run the migrations to 0002 (adding LineString field)
    5155        call_command("migrate", "gis", "0002", verbosity=0)
    52         # Test the new field has been created
     56        # Test the new field has been created, and old one removed
    5357        self.assertFieldExists("gis_neighborhood", "path")
     58        self.assertFieldNotExists("gis_neighborhood", "geom")
    5459        # Unmigrate everything
    5560        call_command("migrate", "gis", "zero", verbosity=0)
    5661        # Make sure it's all gone
Back to Top