def update_wrintermapsreport(session, json_content: dict, last_check: datetime.datetime):
# add current content of intermaps_report to intermaps_history
- pass
+ # the following lines are equivilent to
+ # insert into wrintermapsreporthistory (intermaps_sledrun_id, status, last_update, first_check, utc_offset)
+ # select intermaps_sledrun_id, status, last_update, last_check, utc_offset from wrintermapsreport r
+ # where not exists (select 1 from wrintermapsreporthistory h
+ # where h.intermaps_sledrun_id=r.intermaps_sledrun_id and h.status=r.status and
+ # h.last_update=r.last_update and h.utc_offset=r.utc_offset);
+ q = session.query(WrIntermapsReportHistory) \
+ .filter(WrIntermapsReportHistory.intermaps_sledrun_id == WrIntermapsReport.intermaps_sledrun_id) \
+ .filter(WrIntermapsReportHistory.status == WrIntermapsReport.status) \
+ .filter(WrIntermapsReportHistory.last_update == WrIntermapsReport.last_update) \
+ .filter(WrIntermapsReportHistory.utc_offset == WrIntermapsReport.utc_offset)
+ for report in session.query(WrIntermapsReport).filter(~q.exists()):
+ report_history = WrIntermapsReportHistory()
+ report_history.intermaps_sledrun_id = report.intermaps_sledrun_id
+ report_history.status = report.status
+ report_history.last_update = report.last_update
+ report_history.first_check = report.last_check
+ report_history.utc_offset = report.utc_offset
+ session.add(report_history)
# delete content of intermaps_report
session.query(WrIntermapsReport).delete()