Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024-06-19 | MAIN --> PROD | DEV (af65389) --> STAGING #4004

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions backend/dissemination/sql/create_materialized_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,55 @@ CREATE INDEX IF NOT EXISTS dc_audit_year_idx

CREATE INDEX IF NOT EXISTS dc_aln_idx
on dissemination_combined (aln);


-- Census to GSA Crosswalk
CREATE SEQUENCE IF NOT EXISTS census_gsa_crosswalk_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE;

CREATE MATERIALIZED VIEW IF NOT EXISTS
census_gsa_crosswalk_temp AS
WITH dissemination_general_data_sub_temp AS
(SELECT
dg.report_id,
dg.auditee_uei,
dg.auditee_ein,
substring(dg.report_id, 1, 4) as audit_year,
ltrim(substring(dg.report_id, 16, 25), '0') as dbkey
FROM dissemination_general dg
WHERE dg.report_id ilike '%CENSUS%')
SELECT DISTINCT
nextval('census_gsa_crosswalk_id_seq') AS id,
chmr.audit_year,
chmr.dbkey,
gd.report_id,
gd.auditee_uei,
gd.auditee_ein,
chmr.run_datetime,
chmr.migration_status
FROM census_historical_migration_reportmigrationstatus chmr
INNER JOIN dissemination_general_data_sub_temp gd
ON chmr.audit_year = gd.audit_year AND chmr.dbkey = gd.dbkey
WHERE chmr.migration_status = 'SUCCESS';

DROP MATERIALIZED VIEW IF EXISTS census_gsa_crosswalk;
ALTER SEQUENCE census_gsa_crosswalk_id_seq RESTART;
ALTER MATERIALIZED VIEW census_gsa_crosswalk_temp RENAME TO census_gsa_crosswalk;

CREATE INDEX IF NOT EXISTS cg_crosswalk_report_id_idx
on census_gsa_crosswalk (report_id);

CREATE INDEX IF NOT EXISTS cg_crosswalk_audit_year_idx
on census_gsa_crosswalk (audit_year);

CREATE INDEX IF NOT EXISTS cg_crosswalk_dbkey_idx
on census_gsa_crosswalk (dbkey);

CREATE INDEX IF NOT EXISTS cg_crosswalk_auditee_uei_idx
on census_gsa_crosswalk (auditee_uei);

CREATE INDEX IF NOT EXISTS cg_crosswalk_auditee_ein_idx
on census_gsa_crosswalk (auditee_ein);
4 changes: 4 additions & 0 deletions backend/dissemination/sql/drop_materialized_views.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
DROP MATERIALIZED VIEW IF EXISTS dissemination_combined;

DROP SEQUENCE IF EXISTS dissemination_combined_id_seq;

DROP MATERIALIZED VIEW IF EXISTS census_gsa_crosswalk;

DROP SEQUENCE IF EXISTS census_gsa_crosswalk_id_seq;
2 changes: 2 additions & 0 deletions backend/dissemination/sql/refresh_materialized_views.sql
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
REFRESH MATERIALIZED VIEW dissemination_combined;

REFRESH MATERIALIZED VIEW census_gsa_crosswalk;
Loading