Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion data-archive/archive-jobs/ida_archive_table_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
},
{
"source_table": "otp_transaction",
"archive_table": "mosip_ida_otp_transaction",
"id_column": "id",
"date_column": "cr_dtimes",
"retention_days": 30,
Expand Down
1 change: 0 additions & 1 deletion data-archive/archive-jobs/kernel_archive_table_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"tables_info": [
{
"source_table": "otp_transaction",
"archive_table": "mosip_kernel_otp_transaction",
"id_column": "id",
"date_column": "generated_dtimes",
"retention_days": 7,
Expand Down
33 changes: 25 additions & 8 deletions data-archive/archive-jobs/mosip_archive_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def data_archive(db_name, db_param, tables_info, batch_size):
total_archived = 0
total_deleted = 0
total_batches_processed = 0 # Counter for total batches processed


try:
print(f'Connecting to the PostgreSQL source and archive databases for {db_name}...')
Expand Down Expand Up @@ -215,15 +216,29 @@ def data_archive(db_name, db_param, tables_info, batch_size):

for table_info in tables_info:
source_table_name = table_info['source_table']
archive_table_name = table_info['archive_table']
archive_table_name = table_info.get('archive_table')
id_column = table_info['id_column']
operation_type = table_info.get('operation_type', 'none').lower()
batch_count = 0 # Counter for batches for the current table

# Skip the table if operation_type is 'none'
if operation_type == 'none':
# Validate operation_type-specific fields
if operation_type == 'archive_delete':
if 'archive_table' not in table_info:
print(f"Error: 'archive_table' is required for operation_type 'archive_delete' in table {source_table_name}.")
continue
elif operation_type == 'delete':
if 'archive_table' in table_info:
print(f"Warning: 'archive_table' will be ignored for operation_type 'delete' in table {source_table_name}.")
elif operation_type == 'none':
print(f"Skipping archival for table {source_table_name} as operation type is 'none'.")
continue
else:
print(f"Error: Unsupported operation_type '{operation_type}' for table {source_table_name}.")
continue

# # Skip the table if operation_type is 'none'
# if operation_type == 'none':
# print(f"Skipping archival for table {source_table_name} as operation type is 'none'.")
# continue

# Prepare the select query based on operation type and retention settings
if 'retention_days' in table_info and 'date_column' in table_info:
Expand All @@ -249,6 +264,7 @@ def data_archive(db_name, db_param, tables_info, batch_size):
# Increment the batch count and print
batch_count += 1
print(f"Starting batch {batch_count} for table {source_table_name}...")


# Accumulate records for bulk insert or delete
bulk_insert_values = [get_tablevalues(row) for row in rows]
Expand Down Expand Up @@ -320,11 +336,12 @@ def data_archive(db_name, db_param, tables_info, batch_size):
if archive_conn is not None:
archive_conn.close()
print('Archive database connection closed.')
if total_batches_processed > 0:
print(f"Data archival completed for {db_name}.")
print(f"Total records archived: {total_archived}")
print(f"Total records deleted: {total_deleted}")
print(f"Total batches processed for {db_name}: {total_batches_processed}")

print(f"Data archival completed for {db_name}.")
print(f"Total records archived: {total_archived}")
print(f"Total records deleted: {total_deleted}")
print(f"Total batches processed for {db_name}: {total_batches_processed}")


def main():
Expand Down
1 change: 0 additions & 1 deletion data-archive/archive-jobs/pms_archive_table_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
},
{
"source_table": "notifications",
"archive_table": "",
"id_column": "id",
"date_column": "cr_dtimes",
"retention_days": 60,
Expand Down
1 change: 0 additions & 1 deletion data-archive/archive-jobs/prereg_archive_table_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"tables_info": [
{
"source_table": "otp_transaction",
"archive_table": "mosip_prereg_otp_transaction",
"id_column": "id",
"date_column": "cr_dtimes",
"retention_days": 30,
Expand Down
1 change: 0 additions & 1 deletion data-archive/archive-jobs/resident_archive_table_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"tables_info": [
{
"source_table": "otp_transaction",
"archive_table": "mosip_resident_otp_transaction",
"id_column": "id",
"date_column": "cr_dtimes",
"retention_days": 30,
Expand Down
6 changes: 1 addition & 5 deletions data-archive/db_scripts/mosip_archive/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
\ir ddl/archive-credential-batch_job_instance.sql
\ir ddl/archive-credential-batch_step_execution.sql
\ir ddl/archive-credential-batch_step_execution_context.sql
\ir ddl/archive-ida-credential_event_store.sql
\ir ddl/archive-credential-credential_transaction.sql
\ir ddl/archive-ida-credential_event_store.sql
\ir ddl/archive-esignet-consent_history.sql
\ir ddl/archive-ida-anonymous_profile.sql
\ir ddl/archive-ida-auth_transaction.sql
Expand All @@ -17,11 +17,9 @@
\ir ddl/archive-ida-batch_job_instance.sql
\ir ddl/archive-ida-batch_step_execution_context.sql
\ir ddl/archive-ida-batch_step_execution.sql
\ir ddl/archive-ida-otp_transaction.sql
\ir ddl/archive-idrepo-anonymous_profile.sql
\ir ddl/archive-idrepo-credential_request_status.sql
\ir ddl/archive-idrepo-uin_draft.sql
\ir ddl/archive-kernel-otp_transaction.sql
\ir ddl/archive-master-bulkupload_transaction.sql
\ir ddl/archive-master-device_master_h.sql
\ir ddl/archive-master-machine_master_h.sql
Expand All @@ -31,9 +29,7 @@
\ir ddl/archive-pms-auth_policy_h.sql
\ir ddl/archive-pms-partner_h.sql
\ir ddl/archive-pms-secure_biometric_interface_h.sql
\ir ddl/archive-prereg-otp_transaction.sql
\ir ddl/archive-resident_grievance_ticket.sql
\ir ddl/archive-resident-otp_transaction.sql
\ir ddl/archive-resident_session.sql
\ir ddl/archive-resident_transaction.sql
\ir ddl/archive-resident_user_actions.sql
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading