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

Ongoing - Document existing database model #3188

Closed
jwchumley opened this issue Jun 5, 2018 · 7 comments
Closed

Ongoing - Document existing database model #3188

jwchumley opened this issue Jun 5, 2018 · 7 comments
Assignees
Milestone

Comments

@jwchumley
Copy link
Contributor

Ongoing - Document existing database model to strategize future materialized view work.

@jwchumley jwchumley added this to the Sprint 6.2 milestone Jun 5, 2018
@jwchumley jwchumley modified the milestones: Sprint 6.2, Sprint 6.3 Jun 12, 2018
@vrajmohan
Copy link
Contributor

IIRC, @fecjjeng created an update diagram of the materialized view dependencies. Assigning this issue to @fecjjeng to publish the document (perhaps in the Wiki) and provide a link to it in this issue.

@JonellaCulmer
Copy link
Contributor

@rjayasekera

@vrajmohan vrajmohan assigned rjayasekera and unassigned fecjjeng and wjiangFEC Jun 29, 2018
@rjayasekera
Copy link
Contributor

rjayasekera commented Jul 2, 2018

We use graphviz to generate database object model diagram

  1. Install graphviz by running brew install graphviz
  2. Run following query to to generate object dependencies
SELECT 
'"'||source_ns.nspname||'.'||source_table.relname||'" -> "'||dependent_ns.nspname||'.'||dependent_view.relname||'";'
FROM pg_depend 
JOIN pg_rewrite ON pg_depend.objid = pg_rewrite.oid 
JOIN pg_class as dependent_view ON pg_rewrite.ev_class = dependent_view.oid 
JOIN pg_class as source_table ON pg_depend.refobjid = source_table.oid 
JOIN pg_namespace dependent_ns ON dependent_ns.oid = dependent_view.relnamespace
JOIN pg_namespace source_ns ON source_ns.oid = source_table.relnamespace
WHERE 
-- 
dependent_view.relname like '%_mv' and 
-- dependent_view.relname IN ('list_specific_tables_here') and 
--
dependent_ns.nspname||dependent_view.relname != source_ns.nspname||source_table.relname 
group by dependent_ns.nspname 
, dependent_view.relname  
, source_ns.nspname 
, source_table.relname
order by source_ns.nspname||'.'||source_table.relname, dependent_ns.nspname||'.'||dependent_view.relname;
  1. Copy and paste the output of the query in to a file {name}.dot and surround the query text with graphviz tags and save.
digraph {
    rankdir=LR; #TB UD LR RL
    node [shape="box"];

"auditsearch.audit_case" -> "public.ofec_audit_case_json_test_mv";                                     
"auditsearch.audit_case" -> "public.ofec_audit_case_mv";                                               
"auditsearch.audit_case" -> "public.ofec_candidate_fulltext_audit_mv";                                 
"auditsearch.audit_case" -> "public.ofec_committee_fulltext_audit_mv";
..
..
"staging.ref_rpt_tp" -> "public.ofec_report_pac_party_all_mv";                                         
"staging.ref_zip_to_district" -> "public.ofec_sched_a_aggregate_state_recipient_totals_mv";            
}

4. Run following statement from the directory where you save the above {name}.dot file
dot -Tsvg -o {name}.svg {name}.dot
(Change the output file type by changing  -Tsvg to -Tpdf)

@rjayasekera
Copy link
Contributor

@AmyKort
Copy link

AmyKort commented Jul 6, 2018

With #3165 closed, this shouldn't be blocked. Can I move it to Ready?

@wjiangFEC
Copy link

wjiangFEC commented Jul 6, 2018 via email

@AmyKort
Copy link

AmyKort commented Jul 6, 2018

Closing while we look into a longer term plan.

@AmyKort AmyKort closed this as completed Jul 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants