From e119ced7c11ab93a3109722300f8d76f752e93af Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Fri, 8 Sep 2017 13:26:14 +0100 Subject: [PATCH 1/2] Add command to populate service_email_reply_to: * Insert new entries for unpopulated services * Exclude services who do not have a reply to set --- app/commands.py | 20 ++++++++++++++++++++ application.py | 1 + 2 files changed, 21 insertions(+) diff --git a/app/commands.py b/app/commands.py index a27f08d1b..dd5167ed6 100644 --- a/app/commands.py +++ b/app/commands.py @@ -228,3 +228,23 @@ class BackfillProcessingTime(Command): process_end_date.isoformat() )) send_processing_time_for_start_and_end(process_start_date, process_end_date) + + +class PopulateServiceEmailReplyTo(Command): + + def run(self): + services_to_update = """ + INSERT INTO service_email_reply_to(id, service_id, email_address, is_default, created_at) + SELECT '{}', id, reply_to_email_address, true, '{}' + FROM services + WHERE reply_to_email_address IS NOT NULL + AND id NOT IN( + SELECT service_id + FROM service_email_reply_to + ) + """.format(uuid.uuid4(), datetime.utcnow()) + + result = db.session.execute(services_to_update) + db.session.commit() + + print("Populated email reply to adderesses for {}".format(result.rowcount)) diff --git a/application.py b/application.py index 3127f52af..ab062583b 100644 --- a/application.py +++ b/application.py @@ -18,6 +18,7 @@ manager.add_command('purge_functional_test_data', commands.PurgeFunctionalTestDa manager.add_command('custom_db_script', commands.CustomDbScript) manager.add_command('populate_monthly_billing', commands.PopulateMonthlyBilling) manager.add_command('backfill_processing_time', commands.BackfillProcessingTime) +manager.add_command('populate_service_email_reply_to', commands.PopulateServiceEmailReplyTo) @manager.command From 9bd3ed2dac57fa5cc84a329d5ebc1146f3054a38 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 12 Sep 2017 09:30:55 +0100 Subject: [PATCH 2/2] Use a unique id --- app/commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/commands.py b/app/commands.py index dd5167ed6..3dc3a3d37 100644 --- a/app/commands.py +++ b/app/commands.py @@ -235,14 +235,14 @@ class PopulateServiceEmailReplyTo(Command): def run(self): services_to_update = """ INSERT INTO service_email_reply_to(id, service_id, email_address, is_default, created_at) - SELECT '{}', id, reply_to_email_address, true, '{}' + SELECT uuid_in(md5(random()::text || now()::text)::cstring), id, reply_to_email_address, true, '{}' FROM services WHERE reply_to_email_address IS NOT NULL AND id NOT IN( SELECT service_id FROM service_email_reply_to ) - """.format(uuid.uuid4(), datetime.utcnow()) + """.format(datetime.utcnow()) result = db.session.execute(services_to_update) db.session.commit()