Create a Schema in a Database if It Does Not Exist
Source: R/utils-db.R
Ensures that a specified schema exists in the given database. If the connection is to a MotherDuck instance, the function switches to the specified database before creating the schema. It also prints helpful connection and environment information via CLI messages for transparency.
Usage
create_schema(.con, database_name, schema_name)Arguments
Value
Invisibly returns NULL. Side effect: creates the schema if necessary and prints CLI messages.
Details
-
Uses
DBI::dbExecute()withCREATE SCHEMA IF NOT EXISTSto create the schema only when needed. -
If connected to MotherDuck (determined by
validate_md_connection_status()), executesUSE <database>before creating the schema. -
Displays connection/user/database information via internal CLI helpers.
See Also
Other db-manage: alter_table_schema(), copy_tables_to_new_location(), create_database(), create_if_not_exists_share(), create_or_replace_share(), create_table(), delete_and_create_schema(), delete_database(), delete_schema(), delete_table(), describe_share(), drop_share(), list_owned_shares(), list_shared_with_me_shares(), upload_database_to_md()