diff --git a/raster/migrations/0005_auto_20141014_0955.py b/raster/migrations/0005_auto_20141014_0955.py index 50438ede..bbb36f1e 100644 --- a/raster/migrations/0005_auto_20141014_0955.py +++ b/raster/migrations/0005_auto_20141014_0955.py @@ -1,17 +1,22 @@ # -*- coding: utf-8 -*- from django.db import migrations +def forward(apps, schema_editor): + migrations.RunSQL( + "DROP INDEX IF EXISTS raster_rastertile_rast_st_convexhull_idx;\ + CREATE INDEX raster_rastertile_rast_st_convexhull_idx ON raster_rastertile USING gist( ST_ConvexHull(rast) )" + ) +def reverse(apps, schema_editor): + migrations.RunSQL( + "DROP INDEX IF EXISTS raster_rastertile_rast_st_convexhull_idx" + ) class Migration(migrations.Migration): dependencies = [ ('raster', '0004_rasterlayermetadata'), ] - + operations = [ - migrations.RunSQL( - "DROP INDEX IF EXISTS raster_rastertile_rast_st_convexhull_idx; CREATE INDEX raster_rastertile_rast_st_convexhull_idx\ - ON raster_rastertile USING gist( ST_ConvexHull(rast) )", - "DROP INDEX IF EXISTS raster_rastertile_rast_st_convexhull_idx" - ) - ] + migrations.RunPython(forward, reverse), + ] \ No newline at end of file diff --git a/raster/migrations/0017_copy_srids_20150922_0207.py b/raster/migrations/0017_copy_srids_20150922_0207.py index 7b0a41cd..54bbf8ec 100644 --- a/raster/migrations/0017_copy_srids_20150922_0207.py +++ b/raster/migrations/0017_copy_srids_20150922_0207.py @@ -9,7 +9,8 @@ def move_srid_from_layer_to_metadata_forward(apps, schema_editor): """ RasterLayer = apps.get_model("raster", "RasterLayer") RasterLayerMetadata = apps.get_model("raster", "RasterLayerMetadata") - for lyr in RasterLayer.objects.all(): + db_alias = schema_editor.connection.alias + for lyr in RasterLayer.objects.using(db_alias).all(): meta, created = RasterLayerMetadata.objects.get_or_create(rasterlayer=lyr) meta.srid = lyr.srid meta.save() @@ -20,7 +21,8 @@ def move_srid_from_layer_to_metadata_backward(apps, schema_editor): Copy the srids back to the raster layers. """ RasterLayer = apps.get_model("raster", "RasterLayer") - for lyr in RasterLayer.objects.all(): + db_alias = schema_editor.connection.alias + for lyr in RasterLayer.objects.using(db_alias).all(): if hasattr(lyr, 'rasterlayermetadata'): lyr.srid = lyr.rasterlayermetadata.srid lyr.save() diff --git a/raster/migrations/0022_auto_20151110_0810.py b/raster/migrations/0022_auto_20151110_0810.py index 5393403a..7f9b5f39 100644 --- a/raster/migrations/0022_auto_20151110_0810.py +++ b/raster/migrations/0022_auto_20151110_0810.py @@ -8,7 +8,8 @@ def move_parse_log_to_parse_status_objects_forward(apps, schema_editor): """ RasterLayer = apps.get_model("raster", "RasterLayer") RasterLayerParseStatus = apps.get_model("raster", "RasterLayerParseStatus") - for lyr in RasterLayer.objects.all(): + db_alias = schema_editor.connection.alias + for lyr in RasterLayer.objects.using(db_alias).all(): status, created = RasterLayerParseStatus.objects.get_or_create(rasterlayer=lyr) status.log = lyr.parse_log if 'Successfully finished parsing raster' in lyr.parse_log: @@ -23,7 +24,8 @@ def move_parse_log_to_parse_status_objects_backward(apps, schema_editor): Copy the srids back to the raster layers. """ RasterLayer = apps.get_model("raster", "RasterLayer") - for lyr in RasterLayer.objects.all(): + db_alias = schema_editor.connection.alias + for lyr in RasterLayer.objects.using(db_alias).all(): if hasattr(lyr, 'parsestatus'): lyr.parse_log = lyr.parsestatus.log lyr.save() diff --git a/raster/migrations/0034_legendentryorder.py b/raster/migrations/0034_legendentryorder.py index f1768a2e..849cfbe2 100644 --- a/raster/migrations/0034_legendentryorder.py +++ b/raster/migrations/0034_legendentryorder.py @@ -13,7 +13,8 @@ def move_legend_entries_to_through_model(apps, schema_editor): """ Legend = apps.get_model("raster", "Legend") LegendEntryOrder = apps.get_model("raster", "LegendEntryOrder") - for leg in Legend.objects.all(): + db_alias = schema_editor.connection.alias + for leg in Legend.objects.using(db_alias).all(): for entry in leg.entries.all(): # Respect unique contraint. if LegendEntryOrder.objects.filter(legend=leg, legendentry=entry).exists(): @@ -43,7 +44,8 @@ def move_legend_entries_from_through_model_to_normal_m2m(apps, schema_editor): """ Legend = apps.get_model("raster", "Legend") LegendEntryOrder = apps.get_model("raster", "LegendEntryOrder") - for leg in Legend.objects.all(): + db_alias = schema_editor.connection.alias + for leg in Legend.objects.using(db_alias).all(): for enor in LegendEntryOrder.objects.filter(legend=leg): leg.entries.add(enor.legendentry) diff --git a/raster/migrations/0036_auto_20170509_0548.py b/raster/migrations/0036_auto_20170509_0548.py index db265ab0..dad69f8f 100644 --- a/raster/migrations/0036_auto_20170509_0548.py +++ b/raster/migrations/0036_auto_20170509_0548.py @@ -7,8 +7,9 @@ def set_legend_on_entry(apps, schema_editor): # Get models. Legend = apps.get_model("raster", "Legend") LegendEntryOrder = apps.get_model("raster", "LegendEntryOrder") + db_alias = schema_editor.connection.alias # Loop through legend and entries. - for legend in Legend.objects.all(): + for legend in Legend.objects.using(db_alias).all(): for entry in legend.entries.all(): # Set legend direct foreign key. entry.legend = legend