forked from geosolutions-it/geonode-mapstore-client
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- [Fixes #905] Integrity db error between geoapps tables on upgrade f…
…rom 3.x to 4.x (#906)
- Loading branch information
1 parent
453cc71
commit 76819ab
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
geonode_mapstore_client/migrations/0001_clean_prev_version_geoapps.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import json | ||
|
||
from django.contrib.contenttypes.models import ContentType | ||
from django.db import migrations | ||
|
||
remove_geostories_relation = "DROP TABLE IF EXISTS geoapp_geostories_geostory CASCADE;" | ||
remove_dashboards_relation = "DROP TABLE IF EXISTS geoapp_dashboards_dashboard CASCADE;" | ||
|
||
def update_geostory_dashboard_data(apps, _): | ||
model = apps.get_model('base', 'ResourceBase') | ||
for item in model.objects.filter(resource_type__in=['dashboard', 'geostory']): | ||
if isinstance(item.blob, str): | ||
new_blob = json.loads(item.blob) | ||
model.objects.filter(id=item.id).update(blob=new_blob) | ||
rtype = ContentType.objects.get(model="geoapp") | ||
model.objects.filter(id=item.id).update(polymorphic_ctype=rtype) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.RunPython(update_geostory_dashboard_data, migrations.RunPython.noop), | ||
migrations.RunSQL(remove_geostories_relation), | ||
migrations.RunSQL(remove_dashboards_relation) | ||
] |
Empty file.