Skip to content

Commit

Permalink
Merge pull request #19546 from department-of-veterans-affairs/nkirby/…
Browse files Browse the repository at this point in the history
…APPEALS-30908

nkirby/APPEALS-30908
  • Loading branch information
Aaron-Willis authored Oct 3, 2023
2 parents 1ed29e3 + 6c53c9c commit d19bc9b
Show file tree
Hide file tree
Showing 22 changed files with 381 additions and 369 deletions.
16 changes: 16 additions & 0 deletions Makefile.example
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,22 @@ remove-vbms-ext-claim-seeds: ## Drops audit tables, removes all PriorityEndProdu

reseed-vbms-ext-claim: remove-vbms-ext-claim-seeds seed-vbms-ext-claim ## Re-seeds database with records created from seed-vbms-ext-claim

# Add trigger to vbms_ext_claim to populate pepsq table
add-populate-pepsq-trigger:
bundle exec rails r db/scripts/add_pepsq_populate_trigger_to_vbms_ext_claim.rb

# Add trigger to vbms_ext_claim to populate pepsq table
add-populate-pepsq-trigger-test:
bundle exec rails r -e test db/scripts/add_pepsq_populate_trigger_to_vbms_ext_claim.rb

# Remove populate pepsq trigger from vbms_ext_claim table
drop-populate-pepsq-trigger:
bundle exec rails r db/scripts/drop_pepsq_populate_trigger_from_vbms_ext_claim.rb

# Remove populate pepsq trigger from vbms_ext_claim table
drop-populate-pepsq-trigger-test:
bundle exec rails r -e test db/scripts/drop_pepsq_populate_trigger_from_vbms_ext_claim.rb

c: ## Start rails console
bundle exec rails console

Expand Down
102 changes: 0 additions & 102 deletions app/jobs/populate_end_product_sync_queue_job.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def assign_batch_to_queued_records!(records)
private

# Purpose: Destroys "SYNCED" PEPSQ records to limit the growing number of table records.
# This functionality is needed for the PopulateEndProductSyncQueueJob query to be performant.
#
# Params: None
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

# Model for Priority End Product Sync Queue table.
# This table consists of records of End Product Establishment IDs that need to be synced with VBMS.

# These are populated via the trigger that is created on creation of the vbms_ext_claim table
# The trigger is located in:
# db/scripts/external/create_vbms_ext_claim_table.rb
# db/scripts/
class PriorityEndProductSyncQueue < CaseflowRecord
self.table_name = "priority_end_product_sync_queue"

Expand Down Expand Up @@ -52,7 +57,6 @@ def declare_record_stuck!
end

# Purpose: Destroys "SYNCED" PEPSQ records to limit the growing number of table records.
# This functionality is needed for the PopulateEndProductSyncQueueJob query to be performant.
#
# Params: The batch process the synced records belong to
#
Expand Down
5 changes: 0 additions & 5 deletions config/environments/demo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@
ENV["BATCH_PROCESS_ERROR_DELAY"] ||= "12" # In number of hours
ENV["BATCH_PROCESS_MAX_ERRORS_BEFORE_STUCK"] ||= "3" # When record errors for X time, it's declared stuck

# Populate End Product Sync Queue ENVs
ENV["END_PRODUCT_QUEUE_JOB_DURATION"] ||= "1" # Number of hours the job will run for
ENV["END_PRODUCT_QUEUE_SLEEP_DURATION"] ||= "5" # Number of seconds between loop iterations
ENV["END_PRODUCT_QUEUE_BATCH_LIMIT"] ||= "500" # Max number of records in a batch

# Setup S3
config.s3_enabled = ENV["AWS_BUCKET_NAME"].present?
config.s3_bucket_name = ENV["AWS_BUCKET_NAME"]
Expand Down
5 changes: 0 additions & 5 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@
# Quarterly Notifications Batch Sizes
ENV["QUARTERLY_NOTIFICATIONS_JOB_BATCH_SIZE"] ||= "1000"

# Populate End Product Sync Queue ENVs
ENV["END_PRODUCT_QUEUE_JOB_DURATION"] ||= "50" # Number of minutes the job will run for
ENV["END_PRODUCT_QUEUE_SLEEP_DURATION"] ||= "5" # Number of seconds between loop iterations
ENV["END_PRODUCT_QUEUE_BATCH_LIMIT"] ||= "500" # Max number of records in a batch

# Travel Board Sync Batch Size
ENV["TRAVEL_BOARD_HEARING_SYNC_BATCH_LIMIT"] ||= "250"

Expand Down
5 changes: 0 additions & 5 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@
# Quarterly Notifications Batch Sizes
ENV["QUARTERLY_NOTIFICATIONS_JOB_BATCH_SIZE"] ||= "1000"

# Populate End Product Sync Queue ENVs
ENV["END_PRODUCT_QUEUE_JOB_DURATION"] ||= "50" # Number of minutes the job will run for
ENV["END_PRODUCT_QUEUE_SLEEP_DURATION"] ||= "0" # Number of seconds between loop iterations
ENV["END_PRODUCT_QUEUE_BATCH_LIMIT"] ||= "250" # Max number of records in a batch

# Travel Board Sync Batch Size
ENV["TRAVEL_BOARD_HEARING_SYNC_BATCH_LIMIT"] ||= "250"

Expand Down
1 change: 0 additions & 1 deletion config/initializers/scheduled_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"monthly_metrics" => MonthlyMetricsReportJob,
"nightly_syncs" => NightlySyncsJob,
"out_of_service_reminder" => OutOfServiceReminderJob,
"populate_end_product_sync_queue" => PopulateEndProductSyncQueueJob,
"prepare_establish_claim" => PrepareEstablishClaimTasksJob,
"push_priority_appeals_to_judges" => PushPriorityAppealsToJudgesJob,
"quarterly_metrics" => QuarterlyMetricsReportJob,
Expand Down
51 changes: 51 additions & 0 deletions db/scripts/add_pepsq_populate_trigger_to_vbms_ext_claim.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true

require "pg"

conn = CaseflowRecord.connection
conn.execute("
drop trigger if exists update_claim_status_trigger on vbms_ext_claim;
create or replace function public.update_claim_status_trigger_function()
returns trigger as $$
declare
string_claim_id varchar(25);
epe_id integer;
begin
if (NEW.\"EP_CODE\" LIKE '04%'
OR NEW.\"EP_CODE\" LIKE '03%'
OR NEW.\"EP_CODE\" LIKE '93%'
OR NEW.\"EP_CODE\" LIKE '68%')
and (NEW.\"LEVEL_STATUS_CODE\" = 'CLR' OR NEW.\"LEVEL_STATUS_CODE\" = 'CAN') then
string_claim_id := cast(NEW.\"CLAIM_ID\" as varchar);
select id into epe_id
from end_product_establishments
where (reference_id = string_claim_id
and (synced_status is null or synced_status <> NEW.\"LEVEL_STATUS_CODE\"));
if epe_id > 0
then
if not exists (
select 1
from priority_end_product_sync_queue
where end_product_establishment_id = epe_id
) then
insert into priority_end_product_sync_queue (created_at, end_product_establishment_id, updated_at)
values (now(), epe_id, now());
end if;
end if;
end if;
return null;
end;
$$
language plpgsql;
create trigger update_claim_status_trigger
after update or insert on vbms_ext_claim
for each row
execute procedure public.update_claim_status_trigger_function();
")

conn.close
42 changes: 42 additions & 0 deletions db/scripts/add_pepsq_populate_trigger_to_vbms_ext_claim.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
drop trigger if exists update_claim_status_trigger on vbms_ext_claim;

create or replace function public.update_claim_status_trigger_function()
returns trigger as $$
declare
string_claim_id varchar(25);
epe_id integer;
begin
if (NEW."EP_CODE" LIKE '04%'
OR NEW."EP_CODE" LIKE '03%'
OR NEW."EP_CODE" LIKE '93%'
OR NEW."EP_CODE" LIKE '68%')
and (NEW."LEVEL_STATUS_CODE" = 'CLR' OR NEW."LEVEL_STATUS_CODE" = 'CAN') then

string_claim_id := cast(NEW."CLAIM_ID" as varchar);

select id into epe_id
from end_product_establishments
where (reference_id = string_claim_id
and (synced_status is null or synced_status <> NEW."LEVEL_STATUS_CODE"));

if epe_id > 0
then
if not exists (
select 1
from priority_end_product_sync_queue
where end_product_establishment_id = epe_id
) then
insert into priority_end_product_sync_queue (created_at, end_product_establishment_id, updated_at)
values (now(), epe_id, now());
end if;
end if;
end if;
return null;
end;
$$
language plpgsql;

create trigger update_claim_status_trigger
after update or insert on vbms_ext_claim
for each row
execute procedure public.update_claim_status_trigger_function();
11 changes: 11 additions & 0 deletions db/scripts/drop_pepsq_populate_trigger_from_vbms_ext_claim.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "pg"

conn = CaseflowRecord.connection
conn.execute("
drop trigger if exists update_claim_status_trigger on vbms_ext_claim;
drop function if exists public.update_claim_status_trigger_function();
")

conn.close
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
drop trigger if exists update_claim_status_trigger on vbms_ext_claim;
drop function if exists public.update_claim_status_trigger_function();
2 changes: 2 additions & 0 deletions db/scripts/external/create_vbms_ext_claim_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@
conn.execute('CREATE INDEX IF NOT EXISTS claim_id_index ON public.vbms_ext_claim ("CLAIM_ID")')
conn.execute('CREATE INDEX IF NOT EXISTS level_status_code_index ON public.vbms_ext_claim ("LEVEL_STATUS_CODE")')
conn.close

system("bundle exec rails r db/scripts/add_pepsq_populate_trigger_to_vbms_ext_claim.rb")
43 changes: 43 additions & 0 deletions db/scripts/external/create_vbms_ext_claim_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,46 @@ CREATE TABLE IF NOT EXISTS PUBLIC.VBMS_EXT_CLAIM (
CREATE INDEX IF NOT EXISTS CLAIM_ID_INDEX ON PUBLIC.VBMS_EXT_CLAIM ("CLAIM_ID");

CREATE INDEX IF NOT EXISTS LEVEL_STATUS_CODE_INDEX ON PUBLIC.VBMS_EXT_CLAIM ("LEVEL_STATUS_CODE");

drop trigger if exists update_claim_status_trigger on vbms_ext_claim;

create or replace function public.update_claim_status_trigger_function()
returns trigger as $$
declare
string_claim_id varchar(25);
epe_id integer;
begin
if (NEW."EP_CODE" LIKE '04%'
OR NEW."EP_CODE" LIKE '03%'
OR NEW."EP_CODE" LIKE '93%'
OR NEW."EP_CODE" LIKE '68%')
and (NEW."LEVEL_STATUS_CODE" = 'CLR' OR NEW."LEVEL_STATUS_CODE" = 'CAN') then

string_claim_id := cast(NEW."CLAIM_ID" as varchar);

select id into epe_id
from end_product_establishments
where (reference_id = string_claim_id
and (synced_status is null or synced_status <> NEW."LEVEL_STATUS_CODE"));

if epe_id > 0
then
if not exists (
select 1
from priority_end_product_sync_queue
where end_product_establishment_id = epe_id
) then
insert into priority_end_product_sync_queue (created_at, end_product_establishment_id, updated_at)
values (now(), epe_id, now());
end if;
end if;
end if;
return null;
end;
$$
language plpgsql;

create trigger update_claim_status_trigger
after update or insert on vbms_ext_claim
for each row
execute procedure public.update_claim_status_trigger_function();
3 changes: 3 additions & 0 deletions db/scripts/external/remove_vbms_ext_claim_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
conn.execute(
"drop table IF EXISTS public.vbms_ext_claim;"
)
conn.close

system("bundle exec rails r db/scripts/drop_pepsq_populate_trigger_from_vbms_ext_claim.rb")
Loading

0 comments on commit d19bc9b

Please sign in to comment.