Skip to content

Commit 2612145

Browse files
authored
Merge pull request #2 from sgoley/develop
v0.1.0 - add index & uindex optimizers
2 parents 7a7e566 + ec9b681 commit 2612145

File tree

12 files changed

+82
-0
lines changed

12 files changed

+82
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target/
2+
dbt_modules/
3+
logs/

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,40 @@ Check [dbt Hub](https://hub.getdbt.com/fishtown-analytics/postgres_utils/latest/
99
Postgres Utils is compatible with dbt 0.17.0 and later.
1010

1111
----
12+
13+
## Optimizers
14+
15+
#### index ([source](macros/optimizers/index.sql))
16+
This macro creates an index on a given column.
17+
18+
Usage (at end of model definition .sql file):
19+
```
20+
{{
21+
config({
22+
"post-hook": [
23+
"{{ postgres_utils.index(this, 'id')}}",
24+
],
25+
})
26+
}}
27+
```
28+
29+
#### uindex ([source](macros/optimizers/uindex.sql))
30+
This macro creates an index on a given column.
31+
32+
Usage (at end of model definition .sql file):
33+
```
34+
{{
35+
config({
36+
"post-hook": [
37+
"{{ postgres_utils.uindex(this, 'id')}}",
38+
],
39+
})
40+
}}
41+
```
42+
43+
44+
## Acknowlegements
45+
46+
This project extends fishtown-analytics's own postgres project available here:
47+
48+
https://github.com/fishtown-analytics/postgres (source of index macro)

analysis/.gitkeep

Whitespace-only changes.

data/.gitkeep

Whitespace-only changes.

dbt_project.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: 'postgres_utils'
2+
version: '0.0.1'
3+
4+
require-dbt-version: ">=0.17.0"
5+
6+
source-paths: ["models"]
7+
target-path: "target"
8+
clean-targets: ["target", "dbt_modules"]
9+
test-paths: ["test"]
10+
macro-paths: ["macros"]
11+
log-path: "logs"

macros/.gitkeep

Whitespace-only changes.

macros/optimizers/index.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- original credits to https://github.com/fishtown-analytics/postgres
2+
{% macro index(this, column) %}
3+
4+
create index if not exists "{{ this.name }}__index_on_{{ column }}" on {{ this }} ("{{ column }}")
5+
6+
{% endmacro %}

macros/optimizers/optimizers.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 2
2+
3+
macros:
4+
- name: index
5+
description: creates an index on a given column
6+
arguments:
7+
- name: this
8+
description: Source schema name
9+
- name: column
10+
description: Source schema name
11+
- name: uindex
12+
description: creates an unique index on a given column
13+
arguments:
14+
- name: this
15+
description: Source schema name
16+
- name: column
17+
description: Source schema name

macros/optimizers/uindex.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% macro uindex(this, column) %}
2+
3+
create unique index if not exists "{{ this.name }}__uindex_on_{{ column }}" on {{ this }} ("{{ column }}")
4+
5+
{% endmacro %}

models/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)