rpostgresqlerddm

How to view specific ERD from Postgres database in R using `dm` package


I have built a database with a handful or schemas that have separate entity relationship diagrams (ERDs). I can view those ERDs in my database GUI (dbeaver) but I would like to view schema specific ERDs in RStudio.

I have found the dm package where there is a dm::dm_draw function. The problem is when I call the dm::dm_draw function to my database connection it draws every table and schema in one image. I want to view just one schema. How do I call in and view a specific ERD schema in RStudio?

Below is my attempt of setting the search_path to the 'survey_data' schema as well as passing various arguments into the 'dm::dm_draw' function. I am sorry for not making this fully reproducible but I am not able to provide credentials tot his database.

if (!require(librarian)){
  install.packages("librarian")
  library(librarian)
}
# librarian downloads, if not already downloaded, and reads in needed packages
librarian::shelf(dm, tidyverse, DBI, RPostgres, DiagrammeR)


connection <- dbConnect(drv = dbDriver("Postgres"),
                        dbname = Sys.getenv("aws_dbname"),
                        host = Sys.getenv("aws_host"),
                        port = Sys.getenv("aws_port"),
                        user = Sys.getenv("aws_user"),
                        password = Sys.getenv("aws_password"),
                        options="-c search_path='survey_data'") 

dbExecute(connection,"set search_path = 'survey_data'")


survey_data <- dm_from_con(connection)

survey_data %>% 
  dm_draw(view_type = "all", graph_name = 'survey_data', focus = 'survey_data')



and here is the output of every table being viewed even with all the above attempts to specify just one schema.

all tables


Solution

  • 
    survey_data <- dm_from_con(connection, schema = 'survey_data')
    
    survey_data %>% 
      dm_draw(view_type = "all", rankdir = "RL")