From 865114cba629be5e1a1ea6be03cca17d4db3e90c Mon Sep 17 00:00:00 2001 From: Matt Tuchfarber Date: Mon, 28 Oct 2019 11:10:56 -0400 Subject: [PATCH] Add data migration to fix ecommerce_worker email ecommerce_worker is the only service user with a @fake.email instead of an @example.com email address. This was fixed manually in a devstack sql dump, but was lost during the next sql dump. This will fix it moving forward so we don't have to work around it. --- .../migrations/0008_auto_20191024_2048.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 lms/djangoapps/commerce/migrations/0008_auto_20191024_2048.py diff --git a/lms/djangoapps/commerce/migrations/0008_auto_20191024_2048.py b/lms/djangoapps/commerce/migrations/0008_auto_20191024_2048.py new file mode 100644 index 0000000000..e681647a5f --- /dev/null +++ b/lms/djangoapps/commerce/migrations/0008_auto_20191024_2048.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.25 on 2019-10-24 20:48 +from __future__ import absolute_import, unicode_literals + +from django.conf import settings +from django.db import migrations + +USERNAME = settings.ECOMMERCE_SERVICE_WORKER_USERNAME +NEW_EMAIL = USERNAME + '@example.com' +OLD_EMAIL = USERNAME + '@fake.email' + +class Migration(migrations.Migration): + + def forwards(apps, schema_editor): + """Update the email of the service user.""" + User = apps.get_model("auth", "User") + try: + user = User.objects.get(username=USERNAME, email=OLD_EMAIL) + except User.DoesNotExist: + # Fake email doesn't need to updated if it doesn't exist + return + + user.email = NEW_EMAIL + user.save() + + def backwards(apps, schema_editor): + """Replaces new email with old email for the service user.""" + User = apps.get_model("auth", "User") + try: + user = User.objects.get(username=USERNAME, email=NEW_EMAIL) + except User.DoesNotExist: + # Fake email doesn't need to reverted if it wasn't changed by migration + return + + user.email = OLD_EMAIL + user.save() + + dependencies = [ + ('commerce', '0007_auto_20180313_0609'), + ] + + operations = [ + migrations.RunPython(forwards, backwards), + ] +