Skip to content

Commit

Permalink
- [Fixes GeoNode#905] Integrity db error between geoapps tables on up…
Browse files Browse the repository at this point in the history
…grade from 3.x to 4.x
  • Loading branch information
marthamareal committed Apr 7, 2022
1 parent eecddc1 commit 50955bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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.

0 comments on commit 50955bf

Please sign in to comment.