Skip to content
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

[Feature] Snapshots should respect generate schema/database name macro #10301

Closed
3 tasks done
Tracked by #10151
graciegoheen opened this issue Jun 12, 2024 · 4 comments · Fixed by #10439
Closed
3 tasks done
Tracked by #10151

[Feature] Snapshots should respect generate schema/database name macro #10301

graciegoheen opened this issue Jun 12, 2024 · 4 comments · Fixed by #10439
Assignees
Labels
enhancement New feature or request user docs [docs.getdbt.com] Needs better documentation

Comments

@graciegoheen
Copy link
Contributor

graciegoheen commented Jun 12, 2024

Is this your first time submitting a feature request?

  • I have read the expectations for open source contributors
  • I have searched the existing issues, and I could not find an existing issue for this feature
  • I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

Describe the feature

Historically, snapshots require you set set an explicit target_schema and target_database - meaning by default, regardless of what environment you're in (dev, ci, prod, etc.), when you run dbt snapshot it will build to the same table.

This can be problematic when trying to test out changes to existing snapshot or develop a new snapshot. Now that we have deferral and dbt clone, it no longer makes sense that snapshots wouldn't respect generate_schema_name / generate_database_name like other resources (models, seeds, etc.).

We need to consider backwards compatibility for this change.

Acceptance criteria

  • we makes these old configs optional and if you don't set a target_schema or target_database, we default to using the generate_x_name macros
  • add configs schema and database to be consistent with other resource types (inputs to the generate_x_name macros)
  • continue to accept old names as the "hard-coded" / current experience

Describe alternatives you've considered

Our pal @dbeatty10 often configured his snapshots as so:

{% snapshot my_snapshot %}

{{
    config(
      target_database=target.database,
      target_schema=target.schema,
      …

Our pal @jeremyyeo often does:

{% snapshot snappy %}

{{
    config(
        target_schema=generate_schema_name('snapshots'),
        ...

Relevant docs / discussions

From the snapshots github discussion:
Screenshot 2024-06-10 at 10 56 16 AM
Screenshot 2024-06-10 at 4 23 26 PM
Screenshot 2024-06-12 at 11 40 56 AM

@graciegoheen graciegoheen added enhancement New feature or request triage user docs [docs.getdbt.com] Needs better documentation labels Jun 12, 2024
@graciegoheen
Copy link
Contributor Author

@jtcohen6 do you happen to know why snapshots were originally built with this explicit required override for target_schema? Was this implemented before deferral existed?

@dbeatty10
Copy link
Contributor

dbeatty10 commented Jun 12, 2024

Here's the history I was able to Indiana Jones real quick:

  • dbt 0.5.1 (2016-10-21)
    • Raiders of the Lost Archive -- version your raw data to make historical queries more accurate
    • target_schema: where to archive the data to
  • dbt 0.18.0 (2020-09-03)
    • Added --defer and --state flags to dbt run, to defer to a previously generated manifest for unselected nodes in a run. (#2527, #2656)

@dbeatty10 dbeatty10 removed the triage label Jun 12, 2024
@ChenyuLInx
Copy link
Contributor

ChenyuLInx commented Jun 17, 2024

@QMalcolm this feels like something we should have some tests to capture. And for future features, should we consider adding some guidelines of adding new features(like creating some kind of tests)?

@FishtownBuildBot
Copy link
Collaborator

Opened a new issue in dbt-labs/docs.getdbt.com: dbt-labs/docs.getdbt.com#5806

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request user docs [docs.getdbt.com] Needs better documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants