From 0e7859e538951c31f6fd1e721b8408c7ac983a28 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Wed, 13 Jul 2022 08:19:27 +0200 Subject: [PATCH] Geometry Model geom SRID migration * adds two new migrations for transforming existing geometries into the default SRID --- konova/migrations/0012_auto_20220713_0801.py | 35 ++++++++++++++++++++ konova/migrations/0013_auto_20220713_0814.py | 22 ++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 konova/migrations/0012_auto_20220713_0801.py create mode 100644 konova/migrations/0013_auto_20220713_0814.py diff --git a/konova/migrations/0012_auto_20220713_0801.py b/konova/migrations/0012_auto_20220713_0801.py new file mode 100644 index 00000000..bd6e7645 --- /dev/null +++ b/konova/migrations/0012_auto_20220713_0801.py @@ -0,0 +1,35 @@ +# Generated by Django 3.1.3 on 2022-07-13 06:01 +import django +from django.db import migrations + +from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP + + +def migrate_geometry_srs(apps, schema_editor): + Geometry = apps.get_model("konova", "Geometry") + all_geoms = Geometry.objects.all() + + # Transform all geoms and store in new geom field + for geometry in all_geoms: + geom = geometry.geom + if geom is None: + continue + geom.transform(DEFAULT_SRID_RLP) + geometry.geom_tmp = geom + geometry.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('konova', '0011_auto_20220420_1101'), + ] + + operations = [ + migrations.AddField( + model_name="geometry", + name="geom_tmp", + field=django.contrib.gis.db.models.fields.MultiPolygonField(blank=True, null=True, srid=DEFAULT_SRID_RLP) + ), + migrations.RunPython(migrate_geometry_srs), + ] diff --git a/konova/migrations/0013_auto_20220713_0814.py b/konova/migrations/0013_auto_20220713_0814.py new file mode 100644 index 00000000..c0af268e --- /dev/null +++ b/konova/migrations/0013_auto_20220713_0814.py @@ -0,0 +1,22 @@ +# Generated by Django 3.1.3 on 2022-07-13 06:14 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('konova', '0012_auto_20220713_0801'), + ] + + operations = [ + migrations.RemoveField( + model_name="geometry", + name="geom" + ), + migrations.RenameField( + model_name="geometry", + old_name="geom_tmp", + new_name="geom" + ), + ]