generate_schema_name.sql 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. -- Copyright 2020 Josh Wills. All rights reserved.
  2. -- Copyright Materialize, Inc. and contributors. All rights reserved.
  3. --
  4. -- Licensed under the Apache License, Version 2.0 (the "License");
  5. -- you may not use this file except in compliance with the License.
  6. -- You may obtain a copy of the License in the LICENSE file at the
  7. -- root of this repository, or online at
  8. --
  9. -- http://www.apache.org/licenses/LICENSE-2.0
  10. --
  11. -- Unless required by applicable law or agreed to in writing, software
  12. -- distributed under the License is distributed on an "AS IS" BASIS,
  13. -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. -- See the License for the specific language governing permissions and
  15. -- limitations under the License.
  16. -- Fork of generate_schema_name to add deployment suffix
  17. -- See https://docs.getdbt.com/docs/build/custom-schemas
  18. {% macro materialize__generate_schema_name(custom_schema_name, node) -%}
  19. {%- set default_schema = target.schema -%}
  20. {%- set deploy_suffix = "_dbt_deploy" if var('deploy', False) else "" -%}
  21. {%- if custom_schema_name is none -%}
  22. {{ default_schema }}{{ deploy_suffix }}
  23. {%- else -%}
  24. {{ default_schema }}_{{ custom_schema_name | trim }}{{ deploy_suffix }}
  25. {%- endif -%}
  26. {%- endmacro %}