From 8e944b06224bca15f581b9f9270c91dc6032639b Mon Sep 17 00:00:00 2001 From: Muhammad Umar Khan Date: Tue, 30 Jan 2024 14:07:02 +0500 Subject: [PATCH] feat: add data mmigration to make order_lineattribute value json compatible --- ...ake_lineattribute_value_json_compatible.py | 33 +++++++++++++++++++ ...e.py => 0028_alter_lineattribute_value.py} | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py rename ecommerce/extensions/order/migrations/{0027_alter_lineattribute_value.py => 0028_alter_lineattribute_value.py} (86%) diff --git a/ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py b/ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py new file mode 100644 index 00000000000..3893de30568 --- /dev/null +++ b/ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +from django.core.paginator import Paginator +from django.db import migrations + + +def make_lineattribute_value_json_compatible(apps, schema_editor): + """ + Makes line attribute value json compatible. + """ + LineAttribute = apps.get_model("order", "LineAttribute") + attributes = LineAttribute.objects.order_by('id') + paginator = Paginator(attributes, 1000) + + for page_number in paginator.page_range: + page = paginator.page(page_number) + updates = [] + + for obj in page.object_list: + obj.value = '"{}"'.format(obj.value) + updates.append(obj) + + LineAttribute.objects.bulk_update(updates, ['value']) + + +class Migration(migrations.Migration): + + dependencies = [ + ('order', '0026_auto_20231108_1355'), + ] + + operations = [ + migrations.RunPython(make_lineattribute_value_json_compatible, migrations.RunPython.noop), + ] diff --git a/ecommerce/extensions/order/migrations/0027_alter_lineattribute_value.py b/ecommerce/extensions/order/migrations/0028_alter_lineattribute_value.py similarity index 86% rename from ecommerce/extensions/order/migrations/0027_alter_lineattribute_value.py rename to ecommerce/extensions/order/migrations/0028_alter_lineattribute_value.py index 4bd6caa08e0..b46e66866cb 100644 --- a/ecommerce/extensions/order/migrations/0027_alter_lineattribute_value.py +++ b/ecommerce/extensions/order/migrations/0028_alter_lineattribute_value.py @@ -7,7 +7,7 @@ class Migration(migrations.Migration): dependencies = [ - ('order', '0026_auto_20231108_1355'), + ('order', '0027_make_lineattribute_value_json_compatible'), ] operations = [