diff --git a/.changes/unreleased/Fixes-20240514-193201.yaml b/.changes/unreleased/Fixes-20240514-193201.yaml new file mode 100644 index 00000000..95ab2467 --- /dev/null +++ b/.changes/unreleased/Fixes-20240514-193201.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix the semicolon semantics for indexes while respecting other bug fix +time: 2024-05-14T19:32:01.149383-07:00 +custom: + Author: versusfacit + Issue: "85" diff --git a/dbt/include/postgres/macros/relations/materialized_view/alter.sql b/dbt/include/postgres/macros/relations/materialized_view/alter.sql index ee53c113..429b7e53 100644 --- a/dbt/include/postgres/macros/relations/materialized_view/alter.sql +++ b/dbt/include/postgres/macros/relations/materialized_view/alter.sql @@ -30,13 +30,14 @@ {%- if _index_change.action == "drop" -%} - {{ postgres__get_drop_index_sql(relation, _index.name) }}; + {{ postgres__get_drop_index_sql(relation, _index.name) }} {%- elif _index_change.action == "create" -%} {{ postgres__get_create_index_sql(relation, _index.as_node_config) }} {%- endif -%} + {{ ';' if not loop.last else "" }} {%- endfor -%} diff --git a/dbt/include/postgres/macros/relations/materialized_view/create.sql b/dbt/include/postgres/macros/relations/materialized_view/create.sql index 17e5cb06..89c18234 100644 --- a/dbt/include/postgres/macros/relations/materialized_view/create.sql +++ b/dbt/include/postgres/macros/relations/materialized_view/create.sql @@ -2,7 +2,7 @@ create materialized view if not exists {{ relation }} as {{ sql }}; {% for _index_dict in config.get('indexes', []) -%} - {{- get_create_index_sql(relation, _index_dict) -}} + {{- get_create_index_sql(relation, _index_dict) -}}{{ ';' if not loop.last else "" }} {%- endfor -%} {% endmacro %} diff --git a/tests/functional/test_multiple_indexes.py b/tests/functional/test_multiple_indexes.py new file mode 100644 index 00000000..1d30a6d4 --- /dev/null +++ b/tests/functional/test_multiple_indexes.py @@ -0,0 +1,27 @@ +import pytest + +from tests.functional.utils import run_dbt + + +REF_MULTIPLE_INDEX_MODEL = """ +{{ + config( + materialized="materialized_view", + indexes=[ + {"columns": ["foo"], "type": "btree"}, + {"columns": ["bar"], "type": "btree"}, + ], + ) +}} + +SELECT 1 AS foo, 2 AS bar +""" + + +class TestUnrestrictedPackageAccess: + @pytest.fixture(scope="class") + def models(self): + return {"index_test.sql": REF_MULTIPLE_INDEX_MODEL} + + def test_unrestricted_protected_ref(self, project): + run_dbt()