Skip to content

Commit

Permalink
adding edge cases (#501)
Browse files Browse the repository at this point in the history
Co-authored-by: Marianne Azzopardi <76755256+marazzo@users.noreply.github.com>
  • Loading branch information
mazzopardi2 and marazzo authored May 7, 2024
1 parent 88fa4ae commit 8e1b40b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
4 changes: 2 additions & 2 deletions bin/migration/migration_reports/sql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
'cases': "SELECT COUNT(*) FROM public.cases",
'bookings':"SELECT COUNT(*) FROM public.recordings WHERE parentrecuid = recordinguid and recordingversion = '1'",
'contacts': "SELECT COUNT(*) FROM public.contacts",
'capture_sessions': "SELECT COUNT(*) FROM public.recordings WHERE parentrecuid = recordinguid AND recordingstatus != 'No Recording' AND NOT (recordingstatus = 'Deleted' AND ingestaddress IS NULL)",
'recordings': "SELECT COUNT(*) FROM public.recordings WHERE recordingstatus !='No Recording' AND (recordingavailable IS NULL OR recordingavailable LIKE 'true')",
'capture_sessions': "SELECT COUNT(*) FROM public.recordings WHERE parentrecuid = recordinguid AND (recordingstatus != 'No Recording' OR recordingstatus IS NULL) AND NOT (recordingstatus = 'Deleted' AND ingestaddress IS NULL)",
'recordings': "SELECT COUNT(*) FROM public.recordings WHERE (recordingstatus !='No Recording'OR recordingstatus IS NULL) AND (recordingavailable IS NULL OR recordingavailable LIKE 'true')",
'audits': "SELECT COUNT(*) FROM public.audits",
'share_bookings': "SELECT COUNT(*) FROM public.videopermissions",
'portal_access': """SELECT COUNT(*) AS count_result FROM (
Expand Down
17 changes: 15 additions & 2 deletions bin/migration/tables/capturesessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, source_cursor, logger):

def get_data(self):
self.source_cursor.execute(
"SELECT * FROM public.recordings WHERE parentrecuid = recordinguid AND recordingstatus != 'No Recording' AND NOT (recordingstatus = 'Deleted' AND ingestaddress IS NULL)")
"SELECT * FROM public.recordings WHERE parentrecuid = recordinguid AND (recordingstatus != 'No Recording' OR recordingstatus is NULL) AND NOT (recordingstatus = 'Deleted' AND ingestaddress IS NULL)")
return self.source_cursor.fetchall()

def check_record_in_temp_table(self, destination_cursor, recording_id):
Expand Down Expand Up @@ -96,7 +96,18 @@ def migrate_data(self, destination_cursor, source_data):
(user[0] for user in user_data if user[3] == started_by), None)
deleted_at = parse_to_timestamp(recording[24]) if str(
recording[11]).lower() == 'deleted' else None
status = self.map_recording_status(recording[11])

status = recording[11]
if status:
status = self.map_recording_status(recording[11])
else:
self.failed_imports.append({
'table_name': 'capture_sessions',
'table_id': None,
'recording_id': recording_id,
'details': f"No status listed for recording: {recording_id}"
})
continue

result, booking_not_in_temp_table = self.check_record_in_temp_table(destination_cursor, recording_id)
if result:
Expand All @@ -111,6 +122,8 @@ def migrate_data(self, destination_cursor, source_data):
'details': f"Booking not in temporary recordings table for recording ID: {recording_id}"
})
continue



if temp_recording_batch:
try:
Expand Down
17 changes: 13 additions & 4 deletions bin/migration/tables/participants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ def migrate_data(self, destination_cursor, source_data):
p_type = participant[3]
case_id = participant[4]

if case_id is None:
self.failed_imports.append({
'table_name': 'participants',
'table_id': id,
'case_id': case_id,
'details': f'No case_id detail associated with participant: {id}'
})
continue

if p_type is None:
self.failed_imports.append({
'table_name': 'contacts',
'table_name': 'participants',
'table_id': id,
'case_id': case_id,
'details': f'No participant type detail associated with participant: {id}'
Expand All @@ -37,7 +46,7 @@ def migrate_data(self, destination_cursor, source_data):

if not case_id_exists:
self.failed_imports.append({
'table_name': 'contacts',
'table_name': 'participants',
'table_id': id,
'case_id': case_id,
'details': f'Invalid Case ID: {case_id} associated with participant: {id}'
Expand All @@ -60,7 +69,7 @@ def migrate_data(self, destination_cursor, source_data):
participant_type = p_type.upper()
if participant_type not in ('WITNESS', 'DEFENDANT'):
self.failed_imports.append({
'table_name': 'contacts',
'table_name': 'participants',
'table_id': id,
'case_id': case_id,
'details': f'Invalid participant type: {p_type}.'
Expand Down Expand Up @@ -105,6 +114,6 @@ def migrate_data(self, destination_cursor, source_data):

except Exception as e:
self.failed_imports.append(
{'table_name': 'contacts', 'table_id': id, 'details': str(e)})
{'table_name': 'participants', 'table_id': id, 'details': str(e)})

self.logger.log_failed_imports(self.failed_imports)
12 changes: 8 additions & 4 deletions bin/migration/tables/recordings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ def __init__(self, source_cursor, logger):
def get_data(self):
self.source_cursor.execute(""" SELECT *
FROM public.recordings
WHERE recordingstatus !='No Recording' AND (recordingavailable IS NULL OR
WHERE (recordingstatus !='No Recording' OR recordingstatus IS NULL)
AND (recordingavailable IS NULL OR
recordingavailable LIKE 'true')""")

return self.source_cursor.fetchall()

def get_recording_date_and_user(self, recording_id, activity):
Expand Down Expand Up @@ -90,6 +92,7 @@ def migrate_data(self, destination_cursor, source_data):

created_at_datetime, user_email = self.get_recording_date_and_user(id, "Start")

created_at = None
if created_at_datetime:
created_at = parse_to_timestamp(created_at_datetime)
else:
Expand Down Expand Up @@ -243,7 +246,8 @@ def migrate_data(self, destination_cursor, source_data):
'details': f'Error: Filename exceeds maximum length (255) for recording id {recording_id}'
})
continue


created_at = None
created_at_datetime, user_email = self.get_recording_date_and_user(
recording_id, "Start")
if created_at_datetime:
Expand All @@ -269,8 +273,7 @@ def migrate_data(self, destination_cursor, source_data):
recording_available = recording[13]
if recording_available is None:
deleted_at = datetime.now()
# duration = ? - this info is in the asset files on AMS
# edit_instruction = ?

if parent_recording_id == recording_id:
parent_recording_id = None

Expand All @@ -293,6 +296,7 @@ def migrate_data(self, destination_cursor, source_data):
created_by=created_by if created_by is not None else None,
)
except Exception as e:
destination_cursor.connection.rollback()
self.failed_imports.append(
{'table_name': 'recordings', 'table_id': capture_session_id, 'recording_id': recording_id, 'details': str(e)})

Expand Down

0 comments on commit 8e1b40b

Please sign in to comment.