Mirror a schema's structure (without data) into another schema
Source:R/schema-mirror.R
mirror_schema_structure.RdRecreates the views, materialized views, indexes and functions of
one schema (e.g. camtrap) in another (e.g. camtrap_dev) so the development
schema behaves like production without copying production data. Definitions are
read from the PostgreSQL catalog, so they match what is actually on the server.
Base tables missing from the target are created empty (LIKE ... INCLUDING ALL),
except tables in copy_data_tables (reference data such as the VBA name list),
which are also copied. Objects that already exist in the target are skipped.
Materialized views are built from the target schema's own tables.
By default nothing is changed on the database: the SQL is written to sql_file
for review. Set apply = TRUE to run it in a single transaction.
Usage
mirror_schema_structure(
con,
from = "camtrap",
to = "camtrap_dev",
sql_file = paste0(to, "_setup.sql"),
apply = FALSE,
copy_data_tables = "vba_name_conversions"
)Examples
if (FALSE) { # \dontrun{
con <- weda_connect(password = keyring::key_get(service = "ari-dev-weda-psql-01",
username = "psql_user"))
# Review the SQL first
mirror_schema_structure(con, from = "camtrap", to = "camtrap_dev")
# Then apply it
mirror_schema_structure(con, from = "camtrap", to = "camtrap_dev", apply = TRUE)
} # }