-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CT-1698] [Feature] dbt should default to generate_schema_name_for_env behavior on new projects #6469
Comments
@PedramNavid Thanks for opening this issue — it was a fun read. Sorry for the delayed response, & hope you had a nice holiday break :) I've had a thought similar to yours before: Why do our very own docs present this as a clearly recommended (even preferable!) pattern, without actually making it the default? The new-ish user experienceIt's worth saying that this decision was made a long long time ago (though I can still remember how that music used to make me smile), and it's remained unchanged since then. That's not a reason to keep it around forever—though perhaps it is reason enough to wait until dbt v2—but I also appreciated the prompt to reread the description in Drew's PR from >5 years ago: #522
I stand by this syllogism today. I think it would be more confusing to try adding a custom The current default is decidedly a compromise:
You learn that you can override a subset of built-in dbt behavior, by defining a macro with the same name as a built-in macro. I don't have good data to back this up (we don't collect anonymous usage stats about macro overrides), but I'd guess that I prefer that as a rite of passage, versus the experience of adding a custom schema for the first time and The options are...I think you captured these well. If we did want to change this to be the default, I agree with your tactical proposal for how we'd do it.
I do like the cleanliness of this approach! (Bookkeeping: For a silly reason, we'd also need to make this change in the
This is the status quo, and I'm going to argue that it's not such a big deal. Why?
# packages.yml
packages:
- git: https://github.com/PedramNavid/dbt-pedrams-way
revision: main # dbt_project.yml
dispatch:
- macro_namespace: dbt
search_order: ['dbt_pedrams_way', 'dbt']
# this will prefer 'dbt_pedrams_way.generate_schema_name' over the default 'dbt.generate_schema_name'
# and do the same for all other global macros in the 'dbt' namespace (ok, 3 + 3 = 6 lines of code)
Agreed! This would be really confusing! The behavior of
:) some people just want to watch my dbt Slack DMs burn Airing of grievancesDon't get me wrong — a lot about {% macro default__generate_schema_name(custom_schema_name, node, target) -%}
{% set schema =
(target.schema + "_" + custom_schema_name|trim) if custom_schema_name
else target.schema
-%}
{{ return(schema) }}
{%- endmacro %}
...
{% macro generate_schema_name_for_env(custom_schema_name, node, target) -%}
{%- if target.name == 'prod' and custom_schema_name is not none -%}
{{ return(custom_schema_name | trim) }}
{%- else -%}
{{ return(target.schema) }}
{%- endif -%}
{%- endmacro %} Users could still, of course, pull in If I really had my druthers, I'd also cut |
Thanks for that detailed response @jtcohen6 ! If most people are overriding the default behavior with a custom macro, then the default should be that overridden behavior. A frictionless, simpler user experience is preferable to one that forces the user to consider why something isn't what they expect. For new users learning how to set up schemas, they would be in the docs already reading about how to specify them and where. A note explaining that the schema names, by default, only work in production might be enough? But, given all that, I understand the points against not changing it too. Just thought I'd put my two cents in, but I don't feel too strongly either way! |
I'm going to leave my experiences here working with many projects: I think that "most" folks are not overriding it, but that it's a really good mix. Smaller projects tend to use and need only the defaults, while bigger analytics architecture tends to override these a lot. I'm in favor of keeping the current behavior default as I agree with Jeremy's points about how folks learn what can be done by a need vs. needing to do something they don't quite understand yet. With that said, I do think that the schema override can be simpler. I'm not asking to be able to understand every single need for a custom schema override, just for the most basic one: overriding by environment. How that would be able to be overridden in a simpler way, I don't know - but I have gotten feedback from others that doing one thing from deployment and one thing from development should seem easier than a macro override. Perhaps this could just be a checkbox in Cloud for the deployment environment? (i.e, [ ] Prefix schema configurations with target schema) |
This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days. |
Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest. Just add a comment to notify the maintainers. |
Is this your first time submitting a feature request?
Describe the feature
I have setup many a dbt project, and in every single one, one thing I always end up doing is adding the following macro to
macros/get_custom_schema.sql
.My understanding is that this overrides the default behavior found here.
This pattern comes from dbt's own docs:
https://docs.getdbt.com/docs/build/custom-schemas#an-alternative-pattern-for-generating-schema-names.
I would like to propose that this pattern be the default for new projects. The simplest method is to add the macro to the starter_project, which will prevent any breaking changes.
Describe alternatives you've considered
Who will this benefit?
Both experienced dbt users who have to remember to add this functionality and new dbt users who end up with less-than-ideal first-user-experiences.
I do think this change also ties nicely into #1958
Are you interested in contributing this feature?
Absolutely
Anything else?
I polled 10000 users and they all said they were in favor of this change.
The text was updated successfully, but these errors were encountered: