From 53858473d013887d8318fe90c72678ccf881f2ed Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Fri, 18 Jan 2019 14:51:05 +0000 Subject: [PATCH] Make the replace more specific --- app/commands.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/commands.py b/app/commands.py index 5381a55ac..659037b64 100644 --- a/app/commands.py +++ b/app/commands.py @@ -645,7 +645,7 @@ def update_emails_to_remove_gsi(service_id): JOIN user_to_service us on (u.id = us.user_id) JOIN services s on (s.id = us.service_id) WHERE s.id = :service_id - AND u.email_address ilike ('%.gsi%') + AND u.email_address ilike ('%.gsi.gov.uk%') """ results = db.session.execute(users_to_update, {'service_id': service_id}) print("Updating {} users.".format(results.rowcount)) @@ -653,10 +653,11 @@ def update_emails_to_remove_gsi(service_id): for user in results: print(user) - update_stmt = """UPDATE users - SET email_address = replace(replace(email_address, '.gsi', ''), '.GSI', ''), - updated_at = now() - WHERE id = :user_id + update_stmt = """ + UPDATE users + SET email_address = replace(replace(email_address, '.gsi.gov.uk', '.gov.uk'), '.GSI.GOV.UK', '.GOV.UK'), + updated_at = now() + WHERE id = :user_id """ r = db.session.execute(update_stmt, {'user_id': str(user.user_id)}) db.session.commit()