From 8d08281280f8b26ced0cd4dab8029e9671b985d8 Mon Sep 17 00:00:00 2001 From: Mila Page <67295367+VersusFacit@users.noreply.github.com> Date: Tue, 14 May 2024 20:46:23 -0700 Subject: [PATCH] Fix the semicolon semantics for indexes while respecting other bug fix. (#97) Co-authored-by: Mila Page (cherry picked from commit e23d0a7bb7d4a32598778922ce28578ad4be0e77) --- .../unreleased/Fixes-20240514-193201.yaml | 6 +++++ .../relations/materialized_view/alter.sql | 3 ++- .../relations/materialized_view/create.sql | 2 +- tests/functional/test_multiple_indexes.py | 27 +++++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 .changes/unreleased/Fixes-20240514-193201.yaml create mode 100644 tests/functional/test_multiple_indexes.py 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()