-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
redefine trigger for fec_fitem_sched_b_insert and amend ju
- Loading branch information
1 parent
b22ca9d
commit b5e14b5
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
data/migrations/V0136__redefine_fec_fitem_sched_b_insert.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,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; |