From b5e57321114a0e862f0ad716233a79bf75125056 Mon Sep 17 00:00:00 2001 From: Rajandeep Date: Wed, 11 Feb 2026 15:53:42 -0800 Subject: [PATCH] 32415 - Merge Multiple Dumps from corp_processing table --- data-tool/restore_extract.sh | 54 +++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/data-tool/restore_extract.sh b/data-tool/restore_extract.sh index 6c4e049154..0f91494e82 100755 --- a/data-tool/restore_extract.sh +++ b/data-tool/restore_extract.sh @@ -24,6 +24,7 @@ RESTORE=(corp_processing colin_tracking mig_group mig_batch mig_corp_batch mig_c # -- Runtime options ----------------------------------------------------------- DUMP="${DUMP}" +DELTA_MODE="${DELTA_MODE:-false}" ############################################################################## # INTERNAL HELPERS @@ -51,20 +52,59 @@ printf "🔄 Re‑importing Postgres from Oracle …\n" # -- EMPTY the tables but keep their structure # ############################################################################## printf "🧹 Truncating existing rows …\n" -psql $(pg_conn_opts) -v ON_ERROR_STOP=1 -q <&1 | grep -v "ERROR" || true + psql $(pg_conn_opts) -v ON_ERROR_STOP=0 <<'MERGE' +INSERT INTO corp_processing_old +SELECT * FROM corp_processing +ON CONFLICT (corp_num, flow_name, environment) DO UPDATE +SET + corp_type_cd = EXCLUDED.corp_type_cd, + corp_name = EXCLUDED.corp_name, + filings_count = EXCLUDED.filings_count, + processed_status = EXCLUDED.processed_status, + failed_event_file_type = EXCLUDED.failed_event_file_type, + last_processed_event_id = EXCLUDED.last_processed_event_id, + failed_event_id = EXCLUDED.failed_event_id, + last_error = EXCLUDED.last_error, + claimed_at = EXCLUDED.claimed_at, + flow_run_id = EXCLUDED.flow_run_id, + mig_batch_id = EXCLUDED.mig_batch_id, + account_ids = EXCLUDED.account_ids, + last_modified = EXCLUDED.last_modified; + +DROP TABLE corp_processing; +ALTER TABLE corp_processing_old RENAME TO corp_processing; +MERGE + +else + printf "🚚 Copying preserved rows (constraints temporarily disabled) …\n" + pg_restore $(pg_conn_opts) --section=data --data-only \ + --disable-triggers \ + $(as_table_opts "${RESTORE[@]}") "$DUMP" +fi ############################################################################## # ── FIX ANY SEQUENCES #