Skip to content

Commit

Permalink
redefine trigger for fec_fitem_sched_b_insert and amend ju
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-upchurch committed Jun 7, 2019
1 parent b22ca9d commit b5e14b5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions data/migrations/V0136__redefine_fec_fitem_sched_b_insert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

/*
column election_cycle and two_year_transaction_period in public.ofec_sched_b_master tables has exactly the same data
So disclosure.fec_fitem_sched_b does not add the extra column two_year_transaction_period
However, since existing API referencing column two_year_transaction_period a lot, rename election_cycle to two_year_transaction_period
to mitigate impact to API when switching from using public.ofec_sched_b_master tables to disclosure.fec_fitem_sched_b table
*/

DO $$
BEGIN
EXECUTE format('alter table disclosure.fec_fitem_sched_b rename column election_cycle to two_year_transaction_period');
EXCEPTION
WHEN undefined_column THEN
null;
WHEN others THEN
RAISE NOTICE 'some other error: %, %', sqlstate, sqlerrm;
END$$;

/*
The calculation of value for recipient_name_text in both public.ofec_sched_b and disclosure.fec_fitem_sched_b are slightly incorrect.
It should use clean_recipient_cmte_id instead of recipient_cmte_id.
*/

CREATE OR REPLACE FUNCTION disclosure.fec_fitem_sched_b_insert()
RETURNS trigger AS
$BODY$
begin
new.pdf_url := image_pdf_url(new.image_num);
new.disbursement_description_text := to_tsvector(new.disb_desc);
new.recipient_name_text := to_tsvector(concat(regexp_replace(new.recipient_nm, '[^a-zA-Z0-9]', ' ', 'g')), ' ', new.clean_recipient_cmte_id);
new.disbursement_purpose_category := disbursement_purpose(new.disb_tp, new.disb_desc);
new.line_number_label := expand_line_number(new.filing_form, new.line_num);
return new;
end
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION disclosure.fec_fitem_sched_b_insert()
OWNER TO fec;

0 comments on commit b5e14b5

Please sign in to comment.