From 06b547057e5822bfdff1272c1f8209f12c66bf2a Mon Sep 17 00:00:00 2001 From: Troy Sankey Date: Fri, 28 Feb 2020 11:31:39 -0500 Subject: [PATCH] Add migration to populate site_values in SiteConfigurationHistory Right now the ORM is very unhappy about the JSONField `site_values` in SiteConfigurationHistory containing non-JSON (empty strings). We cannot even write a data migration using the ORM to populate the field because that causes a JSONDeserializationError. Therefore, we must bypass the ORM and populate the values with raw SQL. DENG-18 --- ...populate_siteconfig_history_site_values.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 openedx/core/djangoapps/site_configuration/migrations/0005_populate_siteconfig_history_site_values.py diff --git a/openedx/core/djangoapps/site_configuration/migrations/0005_populate_siteconfig_history_site_values.py b/openedx/core/djangoapps/site_configuration/migrations/0005_populate_siteconfig_history_site_values.py new file mode 100644 index 0000000000..b117380d5b --- /dev/null +++ b/openedx/core/djangoapps/site_configuration/migrations/0005_populate_siteconfig_history_site_values.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations + +forward_sql = """ +UPDATE + site_configuration_siteconfigurationhistory +SET + site_values = '{}'; +""" + +reverse_sql = """ +UPDATE + site_configuration_siteconfigurationhistory +SET + site_values = ''; +""" + + +class Migration(migrations.Migration): + + dependencies = [ + ('site_configuration', '0004_add_site_values_field'), + ] + + operations = [ + migrations.RunSQL(forward_sql, reverse_sql=reverse_sql), + ]