Skip to content

Commit

Permalink
fix: use __get_index_name for dropping index too (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasMTS authored Dec 9, 2024
1 parent d40ec5e commit ce53908
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions dbt/include/risingwave/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,24 @@
{{ return(sql_convert_columns_in_relation(table)) }}
{% endmacro %}

{% macro risingwave__get_index_name(name, columns) -%}
{{ return("__dbt_index_{}_{}".format(name, "_".join(columns))) }}
{% endmacro %}

{% macro risingwave__get_create_index_sql(relation, index_dict) -%}
{%- set index_config = adapter.parse_index(index_dict) -%}
{%- set comma_separated_columns = ", ".join(index_config.columns) -%}
{%- set index_name = "__dbt_index_" + relation.identifier + "_" + "_".join(index_config.columns) -%}
{%- set index_name = risingwave__get_index_name(relation.identifier, index_config.columns) -%}

create index if not exists
"{{ index_name }}"
on {{ relation }}
({{ comma_separated_columns }});
{%- endmacro %}

{%- macro risingwave__get_drop_index_sql(relation, index_name) -%}
drop index if exists "{{ relation.schema }}"."{{ index_name }}"
{%- macro risingwave__get_drop_index_sql(name, columns) -%}
{%- set index_name = risingwave__get_index_name(name, columns) -%}
drop index if exists "{{ index_name }}";
{%- endmacro -%}

{% macro risingwave__drop_relation(relation) -%}
Expand Down Expand Up @@ -164,7 +168,7 @@

{%- if _index_change.action == "drop" -%}

{{ risingwave__get_drop_index_sql(relation, _index.name) }};
{{ risingwave__get_drop_index_sql(_index.name, _index.column_names) }};

{%- elif _index_change.action == "create" -%}

Expand Down

0 comments on commit ce53908

Please sign in to comment.