From 3e1e25b74f3c3767c05aa7b8b667a2aa9a4d74e8 Mon Sep 17 00:00:00 2001 From: Mila Page Date: Tue, 14 May 2024 18:40:43 -0700 Subject: [PATCH] Fix the semicolon semantics for indexes while respecting other bug fix. --- .../relations/materialized_view/alter.sql | 3 ++- .../relations/materialized_view/create.sql | 2 +- tests/functional/test_multiple_indexes.py | 27 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/functional/test_multiple_indexes.py 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()