{% macro clone_prod_to_test(createordrop, dbname, testrole) %}
{% set testdb -%}
"{{ dbname.upper() }}"
{%- endset %}
{% if createordrop == 'create' %}
{% set sql -%}
create database if not exists {{testdb}};
create schema if not exists {{testdb}}.EDW_MODELED clone AFG.EDW_MODELED;
create schema if not exists {{testdb}}.EDW_CONFIG clone AFG.EDW_CONFIG;
create schema if not exists {{testdb}}.EDW_TRANSIENT clone AFG.EDW_TRANSIENT;
create schema if not exists {{testdb}}.ANALYTICS clone AFG.ANALYTICS;
create schema if not exists {{testdb}}.AFGHL clone AFG.AFGHL;
create schema if not exists {{testdb}}.SECURITIES clone AFG.SECURITIES;
create schema if not exists {{testdb}}.CURATED_FLEX clone AFG.CURATED_FLEX;
create schema if not exists {{testdb}}.CURATED_LOANWORKS clone AFG.CURATED_LOANWORKS;
create schema if not exists {{testdb}}.CURATED_DATA_ACTION clone AFG.CURATED_DATA_ACTION;
create schema if not exists {{testdb}}.WH_ANALYTICS clone AFG.WH_ANALYTICS;
create schema if not exists {{testdb}}.WH_AFGHL clone AFG.WH_AFGHL;
create schema if not exists {{testdb}}.WH_SECURITIES clone AFG.WH_SECURITIES;
create schema if not exists {{testdb}}.EDM_EXTERNAL_ORG clone AFG.EDM_EXTERNAL_ORG;
create schema if not exists {{testdb}}.EDM_EXTERNAL clone AFG.EDM_EXTERNAL;
create schema if not exists {{testdb}}.LOGGING clone AFG.LOGGING;
grant usage on database {{testdb}} to role {{ testrole }};
grant usage on all schemas in database {{testdb}} to role {{ testrole }};
grant all on all tables in database {{testdb}} to role {{testrole}};
{%- endset %}
{% else %}
{% set sql -%}
drop database if exists {{testdb}};
{%- endset %}
{% endif %}
{{ dbt_utils.log_info(createordrop ~ " database operation on " ~ dbname ~ " in progress.") }}
{% do run_query(sql) %}
{{ dbt_utils.log_info(createordrop ~ " database operation on " ~ dbname ~ " is completed.") }}
{% endmacro %}