Skip to contents

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

.con

A valid DBI connection (DuckDB / MotherDuck).

database_name

Name of the database to create/use.

schema_name

Name of the schema to create if it does not exist.

Value

Invisibly returns NULL. Side effect: creates the schema if necessary and prints CLI messages.

Details

  • Uses DBI::dbExecute() with CREATE SCHEMA IF NOT EXISTS to create the schema only when needed.

  • If connected to MotherDuck (determined by validate_md_connection_status()), executes USE <database> before creating the schema.

  • Displays connection/user/database information via internal CLI helpers.