diff --git a/bin/migrate-oats-data/common/constants.py b/bin/migrate-oats-data/common/constants.py index a6d58ea21a..11e749c3b8 100644 --- a/bin/migrate-oats-data/common/constants.py +++ b/bin/migrate-oats-data/common/constants.py @@ -1,3 +1,4 @@ OATS_ETL_USER = "oats_etl" BATCH_UPLOAD_SIZE = 1000 NO_DATA_IN_OATS = "No data found in OATS" +DEFAULT_ETL_USER_UUID = "ca8e91dc-cfb0-45c3-a443-8e47e44591df" diff --git a/bin/migrate-oats-data/srw/srw_staff_journal.py b/bin/migrate-oats-data/srw/srw_staff_journal.py index cb47afacfb..b607b02fdd 100644 --- a/bin/migrate-oats-data/srw/srw_staff_journal.py +++ b/bin/migrate-oats-data/srw/srw_staff_journal.py @@ -3,6 +3,7 @@ OATS_ETL_USER, setup_and_get_logger, add_timezone_and_keep_date_part, + DEFAULT_ETL_USER_UUID ) from db import inject_conn_pool from psycopg2.extras import RealDictCursor, execute_batch @@ -114,7 +115,7 @@ def _prepare_journal_data(row_data_list): data = dict(row) data = _map_revision(data) data = _map_timezone(data) - data["user"] = "ca8e91dc-cfb0-45c3-a443-8e47e44591df" + data["user"] = DEFAULT_ETL_USER_UUID data_list.append(dict(data)) return data_list diff --git a/bin/migrate-oats-data/srw/submission/srw_proposal_fields.py b/bin/migrate-oats-data/srw/submission/srw_proposal_fields.py index 505eced71d..a5a3cd162b 100644 --- a/bin/migrate-oats-data/srw/submission/srw_proposal_fields.py +++ b/bin/migrate-oats-data/srw/submission/srw_proposal_fields.py @@ -1,4 +1,4 @@ -from common import BATCH_UPLOAD_SIZE, setup_and_get_logger +from common import BATCH_UPLOAD_SIZE, setup_and_get_logger, DEFAULT_ETL_USER_UUID from db import inject_conn_pool from psycopg2.extras import RealDictCursor, execute_batch @@ -112,7 +112,7 @@ def _prepare_oats_data(row_data_list): def _map_fields(data): return { - "created_by_uuid": data["uuid"], + "created_by_uuid": data["uuid"] if data["uuid"] else DEFAULT_ETL_USER_UUID, "has_survey_plan": data["has_survey_plan"], "purpose": data["summary"], "submitters_file_number": data["applicant_file_no"], diff --git a/bin/migrate-oats-data/staff_journal_users/populate_staff_journal_users.py b/bin/migrate-oats-data/staff_journal_users/populate_staff_journal_users.py index 80dfbfcf23..69cbb6c127 100644 --- a/bin/migrate-oats-data/staff_journal_users/populate_staff_journal_users.py +++ b/bin/migrate-oats-data/staff_journal_users/populate_staff_journal_users.py @@ -1,11 +1,9 @@ -from common import OATS_ETL_USER, setup_and_get_logger +from common import OATS_ETL_USER, setup_and_get_logger, DEFAULT_ETL_USER_UUID from db import inject_conn_pool etl_name = "populate_default_staff_journal_user" logger = setup_and_get_logger(etl_name) -_new_oats_user_uuid = "ca8e91dc-cfb0-45c3-a443-8e47e44591df" - @inject_conn_pool def populate_default_staff_journal_user(conn=None): @@ -13,12 +11,12 @@ def populate_default_staff_journal_user(conn=None): insert_user_query = f""" INSERT INTO alcs."user" (uuid, audit_created_by,email,display_name,preferred_username,"name",given_name,family_name, identity_provider) - VALUES ('{_new_oats_user_uuid}', '{OATS_ETL_USER}','11@11','Oats ETL','Oats ETL','Oats ETL','Oats','ETL', 'etl') + VALUES ('{DEFAULT_ETL_USER_UUID}', '{OATS_ETL_USER}','11@11','Oats ETL','Oats ETL','Oats ETL','Oats','ETL', 'etl') ON CONFLICT DO NOTHING; """ set_user_to_journal_records_query = f""" UPDATE alcs.staff_journal - SET author_uuid = '{_new_oats_user_uuid}' + SET author_uuid = '{DEFAULT_ETL_USER_UUID}' WHERE author_uuid IS NULL AND staff_journal.audit_created_by = '{OATS_ETL_USER}'; """ try: @@ -44,7 +42,7 @@ def clean_staff_journal_users(conn=None): """ delete_query = f""" DELETE FROM alcs.staff_journal - WHERE uuid='{_new_oats_user_uuid}' + WHERE uuid='{DEFAULT_ETL_USER_UUID}' """ try: with conn.cursor() as cursor: