From e6582b90bea29da2e332a304fee98a7112b12d4d Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Thu, 17 Aug 2017 11:50:32 +0100 Subject: [PATCH 1/3] Add db command to update inbound_numbers Updates the service_id with the service.id that matches the sms_sender --- app/commands.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/commands.py b/app/commands.py index 9918b054f..fc9687c66 100644 --- a/app/commands.py +++ b/app/commands.py @@ -151,6 +151,19 @@ class CustomDbScript(Command): db.session.commit() result = db.session.execute(subq_hist).fetchall() + def link_inbound_numbers_to_service(self): + update = """ + UPDATE inbound_numbers SET + service_id = services.id, + updated_at = now() + FROM services + WHERE services.sms_sender = inbound_numbers.number + """ + result = db.session.execute(update) + db.session.commit() + + print("Linked {} inbound numbers to service".format(result.rowcount)) + class PopulateMonthlyBilling(Command): option_list = ( From 39cb66a8820bd11b1326e51766a6954f2d6820da Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Thu, 17 Aug 2017 18:13:17 +0100 Subject: [PATCH 2/3] Update script to only update unassigned inbound --- app/commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/commands.py b/app/commands.py index fc9687c66..15c7aac72 100644 --- a/app/commands.py +++ b/app/commands.py @@ -157,7 +157,8 @@ class CustomDbScript(Command): service_id = services.id, updated_at = now() FROM services - WHERE services.sms_sender = inbound_numbers.number + WHERE services.sms_sender = inbound_numbers.number AND + inbound_numbers.service_id is null """ result = db.session.execute(update) db.session.commit() From 27ccbb0cd1436fed623b2e904923c2e203fe72d0 Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Mon, 21 Aug 2017 13:31:35 +0100 Subject: [PATCH 3/3] Removed trailing whitespace --- app/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/commands.py b/app/commands.py index 15c7aac72..f50508f5c 100644 --- a/app/commands.py +++ b/app/commands.py @@ -157,7 +157,7 @@ class CustomDbScript(Command): service_id = services.id, updated_at = now() FROM services - WHERE services.sms_sender = inbound_numbers.number AND + WHERE services.sms_sender = inbound_numbers.number AND inbound_numbers.service_id is null """ result = db.session.execute(update)