<@U088WCP3B4P> How can i define Elementary's datab...
# ask-elementary-ai
m
@kapa.ai How can i define Elementary's database and schema
k
A message from kapa.ai
You can define Elementary's database and schema in your
dbt_project.yml
file using the following configuration:
Copy code
yaml models:   elementary:     +database: your_database_name     +schema: your_schema_name
This will instruct dbt (and thus Elementary) to create and use the specified database and schema for all Elementary models and tables. Important: - If you use the Elementary CLI (
edr
), make sure your
elementary
profile in
profiles.yml
also points to the same database and schema, so the CLI can read from and write to the correct location. - This approach works across different warehouses (e.g., Snowflake, BigQuery, Postgres), but be aware of any warehouse-specific limitations (e.g., cross-database references in Postgres are not allowed) [FAQ](https://docs.elementary-data.com/oss/general/faq), [Slack discussion](https://slack.com/archives/C02CTC89LAX/p1686886234811099), [Another Slack thread](https://slack.com/archives/C02CTC89LAX/p1666974581573519). If you only want to set the schema (and not the database), you can use:
Copy code
yaml models:   elementary:     +schema: elementary
This will create the Elementary tables in the specified schema within your default database [Quickstart Guide](https://docs.elementary-data.com/oss/quickstart/quickstart-cli-package#step-by-step:install-elementary-dbt-package). Remember to run
dbt run --select elementary
after updating your configuration to apply the changes.
m
@kapa.ai Im using public as prod and dev in my dev env I have in profiles.yml schema "dev_elementary" but when I run edr report I can see public_elementary
k
A message from kapa.ai
The behavior you're seeing is due to how Elementary's CLI (
edr report
) determines which schema to use: it relies solely on the schema defined in the
elementary
profile within your
profiles.yml
, not on any custom schema logic or macros you may have in your dbt project. If you want
edr report
to use
dev_elementary
, you must ensure that the
schema
field under the
elementary
profile in your
profiles.yml
is set to
dev_elementary
and that you are running the CLI with the correct target (if you have multiple targets). For example:
Copy code
yaml elementary:   outputs:     dev:       type: <your_warehouse_type>       ...       schema: dev_elementary       ...   target: dev
If you see
public_elementary
in your report, it means the CLI is connecting to the
public_elementary
schema, likely because that's what is set in your
profiles.yml
or you are using the wrong target when running the command. Key points: - The
edr
CLI does not use your dbt project's
generate_schema_name
macro or any custom schema logic. - It only uses the schema specified in the
elementary
profile in
profiles.yml
for the target you specify. - To switch between environments, define multiple targets (e.g.,
dev
,
prod
) in your
elementary
profile, each with the correct schema, and use the
--profile-target
flag with
edr report
to select the right one. This is a common source of confusion, and is discussed in several community threads and issues. The solution is to explicitly set the schema in your
profiles.yml
and use the correct target when running
edr report
[see Slack discussion](https://slack.com/archives/C02CTC89LAX/p1726599930360009), [GitHub issue](https://github.com/elementary-data/elementary/issues/1462). If you are still seeing the wrong schema, double-check: - The
elementary
profile in your
profiles.yml
is correct. - You are running
edr report
with the correct
--profile-target
if you have multiple targets. Let me know if you need help with the exact
profiles.yml
configuration!