Skip to content

Commit 7adb903

Browse files
authored
Merge pull request #268 from fishtown-analytics/refactor/remove-old-macros
Remove some deprecated macros
2 parents 5f396cc + 7aa8038 commit 7adb903

6 files changed

+29
-47
lines changed

CHANGELOG.md

+28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
# dbt-utils v0.6.0 (unreleased)
22

3+
## Breaking changes
4+
- :rotating_light: dbt v0.18.0 or greater is required for this release. If you are not ready to upgrade, consider using a previous release of this package
5+
- :rotating_light: The `get_tables_by_prefix`, `union_tables` and `get_tables_by_pattern` macros have been removed
6+
7+
## Migration instructions
8+
- Upgrade your dbt project to v0.18.0 using [these instructions](https://discourse.getdbt.com/t/prerelease-v0-18-0-marian-anderson/1545).
9+
- Upgrade your `dbt_project.yml` file to use version `0.7.0`. Run `dbt clean` and `dbt deps`.
10+
- If your project uses the `get_tables_by_prefix` macro, replace it with `get_relations_by_prefix`. All arguments have retained the same name.
11+
- If your project uses the `union_tables` macro, replace it with `union_relations`. While the order of arguments has stayed consistent, the `tables` argument has been renamed to `relations`. Further, the default value for the `source_column_name` argument has changed from `'_dbt_source_table'` to `'_dbt_source_relation'` — you may want to explicitly define this argument to avoid breaking changes.
12+
13+
```
14+
-- before:
15+
{{ dbt_utils.union_tables(
16+
tables=[ref('my_model'), source('my_source', 'my_table')],
17+
exclude=["_loaded_at"]
18+
) }}
19+
20+
-- after:
21+
{{ dbt_utils.union_relations(
22+
relations=[ref('my_model'), source('my_source', 'my_table')],
23+
exclude=["_loaded_at"],
24+
source_column_name='_dbt_source_table'
25+
) }}
26+
```
27+
- If your project uses the `get_tables_by_pattern` macro, replace it with `get_tables_by_pattern_sql` — all arguments are consistent.
28+
329
## Fixes
430

531
## Features
@@ -11,6 +37,8 @@ specific to their database (#267)
1137
database adapters that use different prefixes (#267)
1238

1339
## Quality of life
40+
* Remove deprecated macros `get_tables_by_prefix` and `union_tables` (#268)
41+
* Remove `get_tables_by_pattern` macro, which is equivalent to the `get_tables_by_pattern_sql` macro (the latter has a more logical name)
1442

1543
# dbt-utils v0.5.1
1644

README.md

-5
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,6 @@ Usage:
442442
...
443443
```
444444
#### get_relations_by_prefix
445-
> This replaces the `get_tables_by_prefix` macro. Note that the `get_tables_by_prefix` macro will
446-
be deprecated in a future release of this package.
447-
448445
Returns a list of [Relations](https://docs.getdbt.com/docs/writing-code-in-dbt/class-reference/#relation)
449446
that match a given prefix, with an optional exclusion pattern. It's particularly
450447
handy paired with `union_relations`.
@@ -516,8 +513,6 @@ from {{ref('my_model')}}
516513
```
517514

518515
#### union_relations ([source](macros/sql/union.sql))
519-
> This replaces the `union_tables` macro. Note that the `union_tables` macro will
520-
be deprecated in a future release of this package.
521516

522517
This macro unions together an array of [Relations](https://docs.getdbt.com/docs/writing-code-in-dbt/class-reference/#relation),
523518
even when columns have differing orders in each Relation, and/or some columns are

integration_tests/models/sql/test_get_tables_by_prefix_and_union.sql

-4
This file was deleted.

macros/sql/get_relations_by_pattern.sql

-12
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,3 @@
2121
{%- endif -%}
2222

2323
{% endmacro %}
24-
25-
{% macro get_tables_by_pattern(schema_pattern, table_pattern, exclude='', database=target.database) %}
26-
{%- set error_message = '
27-
Warning: the `get_tables_by_pattern` macro is no longer supported and will be deprecated in a future release of dbt-utils. \
28-
Use the `get_relations_by_prefix` macro instead. \
29-
The {}.{} model triggered this warning. \
30-
'.format(model.package_name, model.name) -%}
31-
{%- do exceptions.warn(error_message) -%}
32-
33-
{{ return(dbt_utils.get_relations_by_pattern(schema_pattern, table_pattern, exclude='', database=target.database)) }}
34-
35-
{% endmacro %}

macros/sql/get_relations_by_prefix.sql

-12
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,3 @@
2121
{%- endif -%}
2222

2323
{% endmacro %}
24-
25-
{% macro get_tables_by_prefix(schema, prefix, exclude='', database=target.database) %}
26-
{%- set error_message = '
27-
Warning: the `get_tables_by_prefix` macro is no longer supported and will be deprecated in a future release of dbt-utils. \
28-
Use the `get_relations_by_prefix` macro instead. \
29-
The {}.{} model triggered this warning. \
30-
'.format(model.package_name, model.name) -%}
31-
{%- do exceptions.warn(error_message) -%}
32-
33-
{{ return(dbt_utils.get_relations_by_prefix(schema, prefix, exclude, database)) }}
34-
35-
{% endmacro %}

macros/sql/union.sql

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{%- macro union_relations(relations, column_override=none, include=[], exclude=[], source_column_name=none) -%}
1+
{%- macro union_relations(relations, column_override=none, include=[], exclude=[], source_column_name='_dbt_source_relation') -%}
22

33
{%- if exclude and include -%}
44
{{ exceptions.raise_compiler_error("Both an exclude and include list were provided to the `union` macro. Only one is allowed") }}
@@ -10,7 +10,6 @@
1010
{% endif -%}
1111

1212
{%- set column_override = column_override if column_override is not none else {} -%}
13-
{%- set source_column_name = source_column_name if source_column_name is not none else '_dbt_source_relation' -%}
1413

1514
{%- set relation_columns = {} -%}
1615
{%- set column_superset = {} -%}
@@ -83,15 +82,3 @@
8382
{%- endfor -%}
8483

8584
{%- endmacro -%}
86-
87-
{%- macro union_tables(tables, column_override=none, include=[], exclude=[], source_column_name='_dbt_source_table') -%}
88-
{%- set error_message = '
89-
Warning: the `union_tables` macro is no longer supported and will be deprecated in a future release of dbt-utils. \
90-
Use the `union_relations` macro instead. \
91-
The {}.{} model triggered this warning. \
92-
'.format(model.package_name, model.name) -%}
93-
{%- do exceptions.warn(error_message) -%}
94-
95-
{{ return(dbt_utils.union_relations(tables, column_override, include, exclude, source_column_name)) }}
96-
97-
{%- endmacro -%}

0 commit comments

Comments
 (0)