Skip to content

Commit 5fde404

Browse files
authored
Merge pull request #2847 from fedspendingtransparency/qat
Sprint 119 Production Deploy
2 parents 50c1c15 + 5e1e578 commit 5fde404

22 files changed

+1210
-509
lines changed
Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,50 @@
11
from django.conf import settings
2-
from django.db import connection
2+
from django import db
33

44

5-
def verify_database_view_exists(view_name: str) -> bool:
5+
def verify_database_view_exists(view_name: str, force_close_conns: bool = False) -> bool:
66
"""Check if the view exists in the target database"""
77
list_views = "SELECT table_name FROM INFORMATION_SCHEMA.views WHERE table_schema = ANY(current_schemas(false))"
8-
with connection.cursor() as cursor:
8+
9+
if force_close_conns:
10+
db.connections.close_all()
11+
12+
with db.connection.cursor() as cursor:
913
cursor.execute(list_views)
1014
list_of_available_views = [row[0] for row in cursor.fetchall()]
1115

1216
return view_name in list_of_available_views
1317

1418

15-
def ensure_view_exists(view_name: str, force: bool = False):
19+
def ensure_view_exists(view_name: str, force: bool = False, force_close_conns: bool = False) -> None:
1620
view_file_path = settings.APP_DIR / "database_scripts" / "etl" / f"{view_name}.sql"
1721

22+
if force_close_conns:
23+
db.connections.close_all()
24+
1825
if verify_database_view_exists(view_name) and not force:
1926
return
2027

2128
view_sql = view_file_path.read_text()
22-
with connection.cursor() as cursor:
29+
with db.connection.cursor() as cursor:
2330
cursor.execute(view_sql)
2431

2532

26-
def ensure_business_categories_functions_exist():
33+
def drop_etl_view(view_name: str, force_close_conns: bool = False) -> None:
34+
"""Drop a view from database using the provided name"""
35+
if force_close_conns:
36+
db.connections.close_all()
37+
38+
with db.connection.cursor() as cursor:
39+
cursor.execute(f"DROP VIEW IF EXISTS {view_name}")
40+
41+
42+
def ensure_business_categories_functions_exist(force_close_conns: bool = False) -> None:
2743
file_path = settings.APP_DIR / "broker" / "management" / "sql" / "create_business_categories_functions.sql"
2844
sql = file_path.read_text()
29-
with connection.cursor() as cursor:
45+
46+
if force_close_conns:
47+
db.connections.close_all()
48+
49+
with db.connection.cursor() as cursor:
3050
cursor.execute(sql)

usaspending_api/common/query_with_filters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def generate_elasticsearch_query(cls, filter_values: List[str], query_type: _Que
2525
"recipient_name",
2626
"naics_description",
2727
"product_or_service_description",
28-
"award_description",
28+
"transaction_description",
2929
"piid",
3030
"fain",
3131
"uri",
@@ -55,7 +55,7 @@ def generate_elasticsearch_query(cls, filter_values: List[str], query_type: _Que
5555
"naics_description",
5656
"product_or_service_code",
5757
"product_or_service_description",
58-
"award_description",
58+
"transaction_description",
5959
"piid",
6060
"fain",
6161
"uri",

usaspending_api/conftest_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
)
1818
from usaspending_api.common.helpers.sql_helpers import ordered_dictionary_fetcher
1919
from usaspending_api.common.helpers.text_helpers import generate_random_string
20-
from usaspending_api.etl.elasticsearch_loader_helpers import create_aliases
20+
from usaspending_api.etl.elasticsearch_loader_helpers import create_award_type_aliases
2121
from usaspending_api.etl.management.commands.es_configure import retrieve_index_template
2222

2323

@@ -52,7 +52,7 @@ def update_index(self, **options):
5252
"""
5353
self.delete_index()
5454
self.client.indices.create(index=self.index_name, body=self.template)
55-
create_aliases(self.client, self.etl_config)
55+
create_award_type_aliases(self.client, self.etl_config)
5656
self._add_contents(**options)
5757

5858
def _add_contents(self, **options):

usaspending_api/data/multiprocessing_worker_names.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
"Monarch",
4545
"Mongoose",
4646
"Moth",
47+
"Neutron",
4748
"Nightmare",
48-
"Nutron",
4949
"Omen",
5050
"Phoenix",
5151
"Protector",
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
DROP VIEW IF EXISTS covid19_faba_view;
2+
CREATE VIEW covid19_faba_view AS
3+
SELECT
4+
faba.financial_accounts_by_awards_id,
5+
faba.piid,
6+
faba.parent_award_id,
7+
faba.fain,
8+
faba.uri,
9+
faba.ussgl480100_undelivered_orders_obligations_unpaid_fyb,
10+
faba.ussgl480100_undelivered_orders_obligations_unpaid_cpe,
11+
faba.ussgl483100_undelivered_orders_oblig_transferred_unpaid_cpe,
12+
faba.ussgl488100_upward_adjust_pri_undeliv_order_oblig_unpaid_cpe,
13+
faba.ussgl490100_delivered_orders_obligations_unpaid_fyb,
14+
faba.ussgl490100_delivered_orders_obligations_unpaid_cpe,
15+
faba.ussgl493100_delivered_orders_oblig_transferred_unpaid_cpe,
16+
faba.ussgl498100_upward_adjust_pri_deliv_orders_oblig_unpaid_cpe,
17+
faba.ussgl480200_undelivered_orders_oblig_prepaid_advanced_fyb,
18+
faba.ussgl480200_undelivered_orders_oblig_prepaid_advanced_cpe,
19+
faba.ussgl483200_undeliv_orders_oblig_transferred_prepaid_adv_cpe,
20+
faba.ussgl488200_up_adjust_pri_undeliv_order_oblig_ppaid_adv_cpe,
21+
faba.ussgl490200_delivered_orders_obligations_paid_cpe,
22+
faba.ussgl490800_authority_outlayed_not_yet_disbursed_fyb,
23+
faba.ussgl490800_authority_outlayed_not_yet_disbursed_cpe,
24+
faba.ussgl498200_upward_adjust_pri_deliv_orders_oblig_paid_cpe,
25+
faba.obligations_undelivered_orders_unpaid_total_cpe,
26+
faba.obligations_delivered_orders_unpaid_total_fyb,
27+
faba.obligations_delivered_orders_unpaid_total_cpe,
28+
faba.gross_outlays_undelivered_orders_prepaid_total_fyb,
29+
faba.gross_outlays_undelivered_orders_prepaid_total_cpe,
30+
faba.gross_outlays_delivered_orders_paid_total_fyb,
31+
faba.gross_outlay_amount_by_award_fyb,
32+
faba.gross_outlay_amount_by_award_cpe,
33+
faba.obligations_incurred_total_by_award_cpe,
34+
faba.ussgl487100_down_adj_pri_unpaid_undel_orders_oblig_recov_cpe,
35+
faba.ussgl497100_down_adj_pri_unpaid_deliv_orders_oblig_recov_cpe,
36+
faba.ussgl487200_down_adj_pri_ppaid_undel_orders_oblig_refund_cpe,
37+
faba.ussgl497200_down_adj_pri_paid_deliv_orders_oblig_refund_cpe,
38+
faba.deobligations_recoveries_refunds_of_prior_year_by_award_cpe,
39+
faba.obligations_undelivered_orders_unpaid_total_fyb,
40+
faba.gross_outlays_delivered_orders_paid_total_cpe,
41+
faba.drv_award_id_field_type,
42+
faba.drv_obligations_incurred_total_by_award,
43+
faba.transaction_obligated_amount,
44+
faba.reporting_period_start,
45+
faba.reporting_period_end,
46+
faba.last_modified_date,
47+
faba.certified_date,
48+
faba.create_date,
49+
faba.update_date,
50+
faba.award_id,
51+
faba.object_class_id,
52+
faba.program_activity_id,
53+
faba.submission_id,
54+
faba.treasury_account_id,
55+
faba.disaster_emergency_fund_code,
56+
faba.distinct_award_key AS financial_account_distinct_award_key,
57+
sa.submission_window_id,
58+
sa.is_final_balances_for_fy,
59+
dabs.submission_fiscal_year,
60+
dabs.submission_fiscal_quarter,
61+
dabs.submission_fiscal_month,
62+
dabs.is_quarter,
63+
dabs.period_start_date,
64+
dabs.period_end_date,
65+
a.id AS funding_toptier_agency_id,
66+
top_a.toptier_code AS funding_toptier_agency_code,
67+
top_a.name AS funding_toptier_agency_name,
68+
taa.tas_rendering_label AS treasury_account_symbol,
69+
taa.account_title AS treasury_account_title,
70+
taa.federal_account_id,
71+
fa.federal_account_code AS federal_account_symbol,
72+
fa.account_title AS federal_account_title,
73+
pa.program_activity_code,
74+
pa.program_activity_name,
75+
oc.major_object_class,
76+
oc.major_object_class_name,
77+
oc.object_class,
78+
oc.object_class_name,
79+
oc.direct_reimbursable,
80+
defc.group_name AS disaster_emergency_fund_code_group_name,
81+
awd.total_loan_value,
82+
awd.type AS award_type,
83+
awd.generated_unique_award_id
84+
FROM financial_accounts_by_awards faba
85+
JOIN submission_attributes sa ON sa.reporting_period_start >= '2020-04-01'::date AND sa.submission_id = faba.submission_id
86+
JOIN disaster_emergency_fund_code defc ON defc.group_name = 'covid_19'::text AND defc.code::text = faba.disaster_emergency_fund_code::text
87+
JOIN dabs_submission_window_schedule dabs ON dabs.submission_reveal_date <= now() AND dabs.id = sa.submission_window_id
88+
LEFT JOIN treasury_appropriation_account taa ON taa.treasury_account_identifier = faba.treasury_account_id
89+
LEFT JOIN toptier_agency top_a ON top_a.toptier_agency_id = taa.funding_toptier_agency_id
90+
LEFT JOIN agency a ON a.toptier_agency_id = top_a.toptier_agency_id AND a.toptier_flag = true
91+
LEFT JOIN federal_account fa ON fa.id = taa.federal_account_id
92+
LEFT JOIN ref_program_activity pa ON pa.id = faba.program_activity_id
93+
LEFT JOIN object_class oc ON oc.id = faba.object_class_id
94+
LEFT JOIN awards awd ON awd.id = faba.award_id
95+
;

0 commit comments

Comments
 (0)