Skip to content

Commit

Permalink
added default etl user uuid to srw (#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuseinov authored Mar 13, 2024
1 parent 7f1a4ff commit efc2034
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions bin/migrate-oats-data/common/constants.py
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 2 additions & 1 deletion bin/migrate-oats-data/srw/srw_staff_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions bin/migrate-oats-data/srw/submission/srw_proposal_fields.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
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):
logger.info(f"Start {etl_name}")

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:
Expand All @@ -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:
Expand Down

0 comments on commit efc2034

Please sign in to comment.