Add command to populate new service letter contact table from existing data

This commit is contained in:
Imdad Ahad
2017-09-25 16:53:15 +01:00
committed by Katie Smith
parent 2614d719d1
commit 1dd3298290
2 changed files with 21 additions and 0 deletions

View File

@@ -285,3 +285,23 @@ class PopulateServiceSmsSender(Command):
print("Populated sms sender {} services from services".format(second_result.rowcount))
print("{} services in table".format(services_count_query))
print("{} service_sms_senders".format(service_sms_sender_count_query))
class PopulateServiceLetterContact(Command):
def run(self):
services_to_update = """
INSERT INTO service_letter_contacts(id, service_id, contact_block, is_default, created_at)
SELECT uuid_in(md5(random()::text || now()::text)::cstring), id, letter_contact_block, true, '{}'
FROM services
WHERE letter_contact_block IS NOT NULL
AND id NOT IN(
SELECT service_id
FROM service_letter_contacts
)
""".format(datetime.utcnow())
result = db.session.execute(services_to_update)
db.session.commit()
print("Populated letter contacts for {} services".format(result.rowcount))