-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1334 from bcgov/develop
Deployment PR - 872
- Loading branch information
Showing
41 changed files
with
391 additions
and
35 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
alcs-frontend/src/app/features/application/decision/decision.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
alcs-frontend/src/app/features/application/proposal/proposal.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
alcs-frontend/src/app/features/notice-of-intent/proposal/proposal.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
bin/migrate-oats-data/applications/sql/application_created_date_update.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT oaa.created_date, oaa.alr_application_id, a.audit_created_by, oaa.when_created | ||
FROM oats.oats_alr_applications oaa | ||
JOIN alcs.application a ON a.file_number = oaa.alr_application_id::TEXT |
3 changes: 3 additions & 0 deletions
3
bin/migrate-oats-data/applications/sql/application_created_date_update_count.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT count(*) | ||
FROM oats.oats_alr_applications oaa | ||
JOIN alcs.application a ON a.file_number = oaa.alr_application_id::TEXT |
116 changes: 116 additions & 0 deletions
116
bin/migrate-oats-data/applications/update_app_created_date.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from common import ( | ||
setup_and_get_logger, | ||
add_timezone_and_keep_date_part, | ||
BATCH_UPLOAD_SIZE | ||
) | ||
from db import inject_conn_pool | ||
from psycopg2.extras import RealDictCursor, execute_batch | ||
|
||
etl_name = "update_application_created_date" | ||
logger = setup_and_get_logger(etl_name) | ||
|
||
|
||
@inject_conn_pool | ||
def update_application_created_date(conn=None, batch_size=BATCH_UPLOAD_SIZE): | ||
""" | ||
This function is responsible for updating existing the application created_at_date in ALCS. | ||
Args: | ||
conn (psycopg2.extensions.connection): PostgreSQL database connection. Provided by the decorator. | ||
batch_size (int): The number of items to process at once. Defaults to BATCH_UPLOAD_SIZE. | ||
""" | ||
|
||
logger.info(f"Start {etl_name}") | ||
with conn.cursor(cursor_factory=RealDictCursor) as cursor: | ||
with open( | ||
"applications/sql/application_created_date_update_count.sql", | ||
"r", | ||
encoding="utf-8", | ||
) as sql_file: | ||
count_query = sql_file.read() | ||
cursor.execute(count_query) | ||
count_total = dict(cursor.fetchone())["count"] | ||
logger.info(f"Total Application data to be updated: {count_total}") | ||
|
||
failed_updates_count = 0 | ||
successful_updates_count = 0 | ||
last_application_id = 0 | ||
|
||
with open( | ||
"applications/sql/application_created_date_update.sql", | ||
"r", | ||
encoding="utf-8", | ||
) as sql_file: | ||
query = sql_file.read() | ||
while True: | ||
cursor.execute( | ||
f"""{query} | ||
WHERE oaa.alr_application_id > {last_application_id} ORDER BY oaa.alr_application_id;""" | ||
) | ||
|
||
rows = cursor.fetchmany(batch_size) | ||
|
||
if not rows: | ||
break | ||
try: | ||
conditions_to_be_updated_count = len(rows) | ||
|
||
_update_application_created_at_date(conn, batch_size, cursor, rows) | ||
|
||
successful_updates_count = ( | ||
successful_updates_count + conditions_to_be_updated_count | ||
) | ||
last_application_id = dict(rows[-1])["alr_application_id"] | ||
|
||
logger.debug( | ||
f"retrieved/updated items count: {conditions_to_be_updated_count}; total successfully updated applications so far {successful_updates_count}; last updated application: {last_application_id}" | ||
) | ||
except Exception as err: | ||
logger.exception(err) | ||
conn.rollback() | ||
failed_updates_count = count_total - successful_updates_count | ||
last_application_id = last_application_id + 1 | ||
|
||
logger.info( | ||
f"Finished {etl_name}: total amount of successful updates {successful_updates_count}, total failed updates {failed_updates_count}" | ||
) | ||
|
||
|
||
def _update_application_created_at_date(conn, batch_size, cursor, rows): | ||
data = _prepare_oats_alr_applications_data(rows) | ||
|
||
if len(data) > 0: | ||
execute_batch( | ||
cursor, | ||
_get_update_query(), | ||
data, | ||
page_size=batch_size, | ||
) | ||
|
||
conn.commit() | ||
|
||
|
||
def _get_update_query(): | ||
query = f""" | ||
UPDATE alcs.application | ||
SET created_at = %(date_to_insert)s | ||
WHERE alcs.application.file_number = %(alr_application_id)s::TEXT; | ||
""" | ||
return query | ||
|
||
|
||
def _prepare_oats_alr_applications_data(row_data_list): | ||
data_list = [] | ||
date_to_insert = None | ||
for row in row_data_list: | ||
if row.get("created_date"): | ||
date_to_insert = row.get("created_date") | ||
else: | ||
date_to_insert = row.get("when_created") | ||
mapped_row = { | ||
"date_to_insert": add_timezone_and_keep_date_part(date_to_insert), | ||
"alr_application_id": row.get("alr_application_id"), | ||
} | ||
data_list.append(mapped_row) | ||
|
||
return data_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...-data/noi/oats_to_alcs_notice_of_intent_table_etl/update_notice_of_intent_created_date.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from common import ( | ||
setup_and_get_logger, | ||
add_timezone_and_keep_date_part, | ||
BATCH_UPLOAD_SIZE | ||
) | ||
from db import inject_conn_pool | ||
from psycopg2.extras import RealDictCursor, execute_batch | ||
|
||
etl_name = "update_notice_of_intent_created_date" | ||
logger = setup_and_get_logger(etl_name) | ||
|
||
|
||
@inject_conn_pool | ||
def update_noi_created_date(conn=None, batch_size=BATCH_UPLOAD_SIZE): | ||
""" | ||
This function is responsible for updating existing the notice_of_intent created_at_date in ALCS. | ||
Args: | ||
conn (psycopg2.extensions.connection): PostgreSQL database connection. Provided by the decorator. | ||
batch_size (int): The number of items to process at once. Defaults to BATCH_UPLOAD_SIZE. | ||
""" | ||
|
||
logger.info(f"Start {etl_name}") | ||
with conn.cursor(cursor_factory=RealDictCursor) as cursor: | ||
with open( | ||
"noi/sql/notice_of_intent_base/notice_of_intent_created_date_update_count.sql", | ||
"r", | ||
encoding="utf-8", | ||
) as sql_file: | ||
count_query = sql_file.read() | ||
cursor.execute(count_query) | ||
count_total = dict(cursor.fetchone())["count"] | ||
logger.info(f"Total Notice of Intent data to be updated: {count_total}") | ||
|
||
failed_updates_count = 0 | ||
successful_updates_count = 0 | ||
last_application_id = 0 | ||
|
||
with open( | ||
"noi/sql/notice_of_intent_base/notice_of_intent_created_date_update.sql", | ||
"r", | ||
encoding="utf-8", | ||
) as sql_file: | ||
query = sql_file.read() | ||
while True: | ||
cursor.execute( | ||
f"""{query} | ||
WHERE oaa.alr_application_id > {last_application_id} ORDER BY oaa.alr_application_id;""" | ||
) | ||
|
||
rows = cursor.fetchmany(batch_size) | ||
|
||
if not rows: | ||
break | ||
try: | ||
conditions_to_be_updated_count = len(rows) | ||
|
||
_update_notice_of_intent_created_at_date(conn, batch_size, cursor, rows) | ||
|
||
successful_updates_count = ( | ||
successful_updates_count + conditions_to_be_updated_count | ||
) | ||
last_application_id = dict(rows[-1])["alr_application_id"] | ||
|
||
logger.debug( | ||
f"retrieved/updated items count: {conditions_to_be_updated_count}; total successfully updated notice of intents so far {successful_updates_count}; last updated notice of intent: {last_application_id}" | ||
) | ||
except Exception as err: | ||
logger.exception(err) | ||
conn.rollback() | ||
failed_updates_count = count_total - successful_updates_count | ||
last_application_id = last_application_id + 1 | ||
|
||
logger.info( | ||
f"Finished {etl_name}: total amount of successful updates {successful_updates_count}, total failed updates {failed_updates_count}" | ||
) | ||
|
||
|
||
def _update_notice_of_intent_created_at_date(conn, batch_size, cursor, rows): | ||
data = _prepare_oats_alr_notice_of_intents_data(rows) | ||
|
||
if len(data) > 0: | ||
execute_batch( | ||
cursor, | ||
_get_update_query(), | ||
data, | ||
page_size=batch_size, | ||
) | ||
|
||
conn.commit() | ||
|
||
|
||
def _get_update_query(): | ||
query = f""" | ||
UPDATE alcs.notice_of_intent | ||
SET created_at = %(date_to_insert)s | ||
WHERE alcs.notice_of_intent.file_number = %(alr_application_id)s::TEXT; | ||
""" | ||
return query | ||
|
||
|
||
def _prepare_oats_alr_notice_of_intents_data(row_data_list): | ||
data_list = [] | ||
date_to_insert = None | ||
for row in row_data_list: | ||
if row.get("created_date"): | ||
date_to_insert = row.get("created_date") | ||
else: | ||
date_to_insert = row.get("when_created") | ||
mapped_row = { | ||
"date_to_insert": add_timezone_and_keep_date_part(date_to_insert), | ||
"alr_application_id": row.get("alr_application_id"), | ||
} | ||
data_list.append(mapped_row) | ||
|
||
return data_list |
3 changes: 3 additions & 0 deletions
3
bin/migrate-oats-data/noi/sql/notice_of_intent_base/notice_of_intent_created_date_update.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT oaa.created_date, oaa.alr_application_id, oaa.when_created | ||
FROM oats.oats_alr_applications oaa | ||
JOIN alcs.notice_of_intent noi ON noi.file_number = oaa.alr_application_id::TEXT |
3 changes: 3 additions & 0 deletions
3
...te-oats-data/noi/sql/notice_of_intent_base/notice_of_intent_created_date_update_count.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT count(*) | ||
FROM oats.oats_alr_applications oaa | ||
JOIN alcs.notice_of_intent noi ON noi.file_number = oaa.alr_application_id::TEXT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.