-
Notifications
You must be signed in to change notification settings - Fork 175
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-427] When cloning an entire database, I'd like to recreate all views to redirect references from self to the newly cloned self #118
Comments
@ybressler Thanks for opening, and sorry for the delay getting back to you! Bad solutionAs you mention, this would do the trick:
It's just not the most savory of solutions :) Better solutionThis is exactly the question you raised in dbt-labs/dbt-core#4959. It's possible (and pretty easy) to override Docs: https://docs.getdbt.com/reference/dbt-jinja-functions/builtins The trade-off is, if you do this all the time, you can't create your objects across multiple databases. I remember working on a project that wanted it both ways, and ended up setting a rule like:
-- Render identifiers without a database if the current model is materialized as a view.
-- Otherwise, include the database.
{% macro ref(model_name) %}
{% set rel = builtins.ref(model_name) %}
{% set not_a_view = (config.get('materialized') != 'view') %}
{% do return(rel.include(database=not_a_view)) %}
{% endmacro %} Best solution???I completely buy the thing you're saying here:
I think we'll see cloning supported by more databases, and it will be all-the-more important for dbt to support a built-in I've also long wanted to support a "clone" mode of Following that approach, dbt could clone upstream objects "as needed." Cloning a table would look like cloning a table. Cloning a view may look like cloning + rewriting refs, or (much simpler) just running that view. If you're running hundreds of models, the accumulated time of doing this is probably more than a one-shot |
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 remove the stale label or comment on the issue, or it will be closed in 7 days. |
Describe the feature
When cloning an entire database, any views being cloned will retain their original SQL statements. In the case where these views contain references to the current DB (parent), I want these references to be redirected to the cloned DB (child). Additionally, if I am cloning multiple DB's, it would be great to be able to point any references via a mapping – ex. provide a python dictionary (or yaml eq) and have any references overwritten or redirected.
Describe alternatives you've considered
Additional context
Currently, cloning occurs as a SQL command to Snowflake – DBT doesn't have a built in way of being aware of these changes. The only way to transmit these changes is to switch targets and assume naively that everything magically appeared (which is fine for the most part, but can lead to issues in cases like these).
Who will this benefit?
Anyone using DBT with Snowflake who has considered or is already using cloning. (As an aside, Snowflake's zero copy cloning is one of its features which sets it apart from its competitors – it would be incredibly valuable to have a more DBT-native solution available).
Are you interested in contributing this feature?
Certainly I am, but would need to have someone else own the project management of this task. (I can do this "on the side" so to say.)
The text was updated successfully, but these errors were encountered: