Changes following review:

- Check if right keys in new history rows
- Improve model and get rid of old revision version
- Add updated migration file
- Test data when inserting into inbound sms history
This commit is contained in:
Pea Tyczynska
2019-12-20 12:34:59 +00:00
parent 448cd1e94e
commit f8ff2d121f
4 changed files with 36 additions and 11 deletions

View File

@@ -63,7 +63,7 @@ def dao_count_inbound_sms_for_service(service_id, limit_days):
).count()
def _insert_update_notification_history(subquery, query_limit=10000):
def _insert_update_inbound_sms_history(subquery, query_limit=10000):
offset = 0
inbound_sms_query = db.session.query(
*[x.name for x in InboundSmsHistory.__table__.c]
@@ -79,7 +79,6 @@ def _insert_update_notification_history(subquery, query_limit=10000):
statement = statement.on_conflict_do_update(
constraint="inbound_sms_history_pkey",
set_={
"created_at": statement.excluded.created_at,
"service_id": statement.excluded.service_id,
"notify_number": statement.excluded.notify_number,
"provider_date": statement.excluded.provider_date,
@@ -108,7 +107,7 @@ def _delete_inbound_sms(datetime_to_delete_from, query_filter):
# set to nonzero just to enter the loop
number_deleted = 1
while number_deleted > 0:
_insert_update_notification_history(subquery, query_limit=query_limit)
_insert_update_inbound_sms_history(subquery, query_limit=query_limit)
number_deleted = InboundSms.query.filter(InboundSms.id.in_(subquery)).delete(synchronize_session='fetch')
deleted += number_deleted