deploy_cleanup.sql 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. -- Copyright Materialize, Inc. and contributors. All rights reserved.
  2. --
  3. -- Licensed under the Apache License, Version 2.0 (the "License");
  4. -- you may not use this file except in compliance with the License.
  5. -- You may obtain a copy of the License in the LICENSE file at the
  6. -- root of this repository, or online at
  7. --
  8. -- http://www.apache.org/licenses/LICENSE-2.0
  9. --
  10. -- Unless required by applicable law or agreed to in writing, software
  11. -- distributed under the License is distributed on an "AS IS" BASIS,
  12. -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. -- See the License for the specific language governing permissions and
  14. -- limitations under the License.
  15. {% macro deploy_cleanup() %}
  16. {% set current_target_name = target.name %}
  17. {% set deployment = var('deployment') %}
  18. {% set target_config = deployment[current_target_name] %}
  19. -- Check if the target-specific configuration exists
  20. {% if not target_config %}
  21. {{ exceptions.raise_compiler_error("No deployment configuration found for target " ~ current_target_name) }}
  22. {% endif %}
  23. {{ log("Dropping deployment environment for target " ~ current_target_name, info=True) }}
  24. {% set clusters = target_config.get('clusters', []) %}
  25. {% set schemas = target_config.get('schemas', []) %}
  26. {% for schema in schemas %}
  27. {% set deploy_schema = schema ~ "_dbt_deploy" %}
  28. {{ log("Dropping schema " ~ deploy_schema ~ " for target " ~ current_target_name, info=True) }}
  29. {% set drop_schema %}
  30. DROP SCHEMA IF EXISTS {{ adapter.quote(deploy_schema) }} CASCADE;
  31. {% endset %}
  32. {{ run_query(drop_schema) }}
  33. {% endfor %}
  34. {% for cluster in clusters %}
  35. {% set deploy_cluster = adapter.generate_final_cluster_name(cluster, force_deploy_suffix=True) %}
  36. {{ log("Dropping cluster " ~ deploy_cluster ~ " for target " ~ current_target_name, info=True) }}
  37. {% set drop_cluster %}
  38. DROP CLUSTER IF EXISTS {{ adapter.quote(deploy_cluster) }} CASCADE;
  39. {% endset %}
  40. {{ run_query(drop_cluster) }}
  41. {% endfor %}
  42. {% endmacro %}