dbt-postgres 1.8.2__tar.gz → 1.9.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/PKG-INFO +11 -7
  2. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/README.md +5 -0
  3. dbt_postgres-1.9.0/dbt/adapters/postgres/__version__.py +1 -0
  4. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/adapters/postgres/connections.py +25 -9
  5. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/adapters/postgres/impl.py +1 -1
  6. dbt_postgres-1.9.0/dbt/adapters/postgres/record/__init__.py +2 -0
  7. dbt_postgres-1.9.0/dbt/adapters/postgres/record/cursor/cursor.py +15 -0
  8. dbt_postgres-1.9.0/dbt/adapters/postgres/record/cursor/status.py +21 -0
  9. dbt_postgres-1.9.0/dbt/adapters/postgres/record/handle.py +12 -0
  10. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/adapters.sql +6 -1
  11. dbt_postgres-1.9.0/dbt/include/postgres/macros/materializations/incremental_strategies.sql +20 -0
  12. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/materializations/snapshot_merge.sql +10 -3
  13. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/pyproject.toml +19 -28
  14. dbt_postgres-1.8.2/dbt/adapters/postgres/__version__.py +0 -1
  15. dbt_postgres-1.8.2/dbt/include/postgres/macros/materializations/incremental_strategies.sql +0 -9
  16. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/.gitignore +0 -0
  17. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/LICENSE +0 -0
  18. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/__init__.py +0 -0
  19. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/adapters/postgres/__init__.py +0 -0
  20. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/adapters/postgres/column.py +0 -0
  21. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/adapters/postgres/relation.py +0 -0
  22. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/adapters/postgres/relation_configs/__init__.py +0 -0
  23. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/adapters/postgres/relation_configs/constants.py +0 -0
  24. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/adapters/postgres/relation_configs/index.py +0 -0
  25. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/adapters/postgres/relation_configs/materialized_view.py +0 -0
  26. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/__init__.py +0 -0
  27. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/dbt_project.yml +0 -0
  28. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/catalog.sql +0 -0
  29. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/relations/materialized_view/alter.sql +0 -0
  30. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/relations/materialized_view/create.sql +0 -0
  31. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/relations/materialized_view/describe.sql +0 -0
  32. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/relations/materialized_view/drop.sql +0 -0
  33. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/relations/materialized_view/refresh.sql +0 -0
  34. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/relations/materialized_view/rename.sql +0 -0
  35. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/relations/table/drop.sql +0 -0
  36. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/relations/table/rename.sql +0 -0
  37. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/relations/table/replace.sql +0 -0
  38. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/relations/view/drop.sql +0 -0
  39. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/relations/view/rename.sql +0 -0
  40. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/relations/view/replace.sql +0 -0
  41. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/relations.sql +0 -0
  42. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/timestamps.sql +0 -0
  43. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/utils/any_value.sql +0 -0
  44. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/utils/columns_spec_ddl.sql +0 -0
  45. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/utils/dateadd.sql +0 -0
  46. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/utils/datediff.sql +0 -0
  47. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/utils/last_day.sql +0 -0
  48. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/utils/listagg.sql +0 -0
  49. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/macros/utils/split_part.sql +0 -0
  50. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/profile_template.yml +0 -0
  51. {dbt_postgres-1.8.2 → dbt_postgres-1.9.0}/dbt/include/postgres/sample_profiles.yml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dbt-postgres
3
- Version: 1.8.2
3
+ Version: 1.9.0
4
4
  Summary: The set of adapter protocols and base functionality that supports integration with dbt-core
5
5
  Project-URL: Homepage, https://github.com/dbt-labs/dbt-postgres
6
6
  Project-URL: Documentation, https://docs.getdbt.com
@@ -9,22 +9,21 @@ Project-URL: Issues, https://github.com/dbt-labs/dbt-postgres/issues
9
9
  Project-URL: Changelog, https://github.com/dbt-labs/dbt-postgres/blob/main/CHANGELOG.md
10
10
  Author-email: dbt Labs <info@dbtlabs.com>
11
11
  Maintainer-email: dbt Labs <info@dbtlabs.com>
12
- License-File: LICENSE
13
12
  Keywords: adapter,adapters,database,dbt,dbt Cloud,dbt Core,dbt Labs,dbt-core,elt,postgres
14
13
  Classifier: Development Status :: 5 - Production/Stable
15
14
  Classifier: License :: OSI Approved :: Apache Software License
16
15
  Classifier: Operating System :: MacOS :: MacOS X
17
16
  Classifier: Operating System :: Microsoft :: Windows
18
17
  Classifier: Operating System :: POSIX :: Linux
19
- Classifier: Programming Language :: Python :: 3.8
20
18
  Classifier: Programming Language :: Python :: 3.9
21
19
  Classifier: Programming Language :: Python :: 3.10
22
20
  Classifier: Programming Language :: Python :: 3.11
23
- Requires-Python: >=3.8.0
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Requires-Python: >=3.9.0
24
23
  Requires-Dist: agate<2.0,>=1.0
25
- Requires-Dist: dbt-adapters<2.0,>=0.1.0a1
26
- Requires-Dist: dbt-common<2.0,>=0.1.0a1
27
- Requires-Dist: dbt-core>=1.8.0a1
24
+ Requires-Dist: dbt-adapters<2.0,>=1.7.0
25
+ Requires-Dist: dbt-common<2.0,>=1.0.4
26
+ Requires-Dist: dbt-core>=1.8.0
28
27
  Requires-Dist: psycopg2-binary<3.0,>=2.9
29
28
  Description-Content-Type: text/markdown
30
29
 
@@ -65,6 +64,11 @@ fi
65
64
 
66
65
  This ensures the version of `psycopg2` will match that of `psycopg2-binary`.
67
66
 
67
+
68
+ ## Contribute
69
+
70
+ See `CONTRIBUTING.md` for a detailed overview of contributing a code change to this adapter.
71
+
68
72
  ## Join the dbt Community
69
73
 
70
74
  - Be part of the conversation in the [dbt Community Slack](http://community.getdbt.com/)
@@ -35,6 +35,11 @@ fi
35
35
 
36
36
  This ensures the version of `psycopg2` will match that of `psycopg2-binary`.
37
37
 
38
+
39
+ ## Contribute
40
+
41
+ See `CONTRIBUTING.md` for a detailed overview of contributing a code change to this adapter.
42
+
38
43
  ## Join the dbt Community
39
44
 
40
45
  - Be part of the conversation in the [dbt Community Slack](http://community.getdbt.com/)
@@ -0,0 +1 @@
1
+ version = "1.9.0"
@@ -5,10 +5,12 @@ from typing import Optional, Union
5
5
  from dbt.adapters.contracts.connection import AdapterResponse, Credentials
6
6
  from dbt.adapters.events.logging import AdapterLogger
7
7
  from dbt.adapters.events.types import TypeCodeNotFound
8
+ from dbt.adapters.postgres.record import PostgresRecordReplayHandle
8
9
  from dbt.adapters.sql import SQLConnectionManager
9
10
  from dbt_common.exceptions import DbtDatabaseError, DbtRuntimeError
10
11
  from dbt_common.events.functions import warn_or_error
11
12
  from dbt_common.helper_types import Port
13
+ from dbt_common.record import get_record_mode_from_env, RecorderMode
12
14
  from mashumaro.jsonschema.annotations import Maximum, Minimum
13
15
  import psycopg2
14
16
  from typing_extensions import Annotated
@@ -132,17 +134,31 @@ class PostgresConnectionManager(SQLConnectionManager):
132
134
  kwargs["application_name"] = credentials.application_name
133
135
 
134
136
  def connect():
135
- handle = psycopg2.connect(
136
- dbname=credentials.database,
137
- user=credentials.user,
138
- host=credentials.host,
139
- password=credentials.password,
140
- port=credentials.port,
141
- connect_timeout=credentials.connect_timeout,
142
- **kwargs,
143
- )
137
+ handle = None
138
+
139
+ # In replay mode, we won't connect to a real database at all, while
140
+ # in record and diff modes we do, but insert an intermediate handle
141
+ # object which monitors native connection activity.
142
+ rec_mode = get_record_mode_from_env()
143
+ if rec_mode != RecorderMode.REPLAY:
144
+ handle = psycopg2.connect(
145
+ dbname=credentials.database,
146
+ user=credentials.user,
147
+ host=credentials.host,
148
+ password=credentials.password,
149
+ port=credentials.port,
150
+ connect_timeout=credentials.connect_timeout,
151
+ **kwargs,
152
+ )
153
+
154
+ if rec_mode is not None:
155
+ # If using the record/replay mechanism, regardless of mode, we
156
+ # use a wrapper.
157
+ handle = PostgresRecordReplayHandle(handle, connection)
158
+
144
159
  if credentials.role:
145
160
  handle.cursor().execute("set role {}".format(credentials.role))
161
+
146
162
  return handle
147
163
 
148
164
  retryable_exceptions = [
@@ -151,7 +151,7 @@ class PostgresAdapter(SQLAdapter):
151
151
  """The set of standard builtin strategies which this adapter supports out-of-the-box.
152
152
  Not used to validate custom strategies defined by end users.
153
153
  """
154
- return ["append", "delete+insert", "merge"]
154
+ return ["append", "delete+insert", "merge", "microbatch"]
155
155
 
156
156
  def debug_query(self):
157
157
  self.execute("select 1 as id")
@@ -0,0 +1,2 @@
1
+ from dbt.adapters.postgres.record.cursor.cursor import PostgresRecordReplayCursor
2
+ from dbt.adapters.postgres.record.handle import PostgresRecordReplayHandle
@@ -0,0 +1,15 @@
1
+ from dbt_common.record import record_function
2
+
3
+ from dbt.adapters.record import RecordReplayCursor
4
+
5
+ from dbt.adapters.postgres.record.cursor.status import CursorGetStatusMessageRecord
6
+
7
+
8
+ class PostgresRecordReplayCursor(RecordReplayCursor):
9
+ """A custom extension of RecordReplayCursor that adds the statusmessage
10
+ property which is specific to psycopg."""
11
+
12
+ @property
13
+ @record_function(CursorGetStatusMessageRecord, method=True, id_field_name="connection_name")
14
+ def statusmessage(self):
15
+ return self.native_cursor.statusmessage
@@ -0,0 +1,21 @@
1
+ import dataclasses
2
+ from typing import Optional
3
+
4
+ from dbt_common.record import Record, Recorder
5
+
6
+
7
+ @dataclasses.dataclass
8
+ class CursorGetStatusMessageParams:
9
+ connection_name: str
10
+
11
+
12
+ @dataclasses.dataclass
13
+ class CursorGetStatusMessageResult:
14
+ msg: Optional[str]
15
+
16
+
17
+ @Recorder.register_record_type
18
+ class CursorGetStatusMessageRecord(Record):
19
+ params_cls = CursorGetStatusMessageParams
20
+ result_cls = CursorGetStatusMessageResult
21
+ group = "Database"
@@ -0,0 +1,12 @@
1
+ from dbt.adapters.record import RecordReplayHandle
2
+
3
+ from dbt.adapters.postgres.record.cursor.cursor import PostgresRecordReplayCursor
4
+
5
+
6
+ class PostgresRecordReplayHandle(RecordReplayHandle):
7
+ """A custom extension of RecordReplayHandle that returns
8
+ a psycopg-specific PostgresRecordReplayCursor object."""
9
+
10
+ def cursor(self):
11
+ cursor = None if self.native_handle is None else self.native_handle.cursor()
12
+ return PostgresRecordReplayCursor(cursor, self.connection)
@@ -196,7 +196,12 @@
196
196
 
197
197
  {% macro postgres__alter_relation_comment(relation, comment) %}
198
198
  {% set escaped_comment = postgres_escape_comment(comment) %}
199
- comment on {{ relation.type }} {{ relation }} is {{ escaped_comment }};
199
+ {% if relation.type == 'materialized_view' -%}
200
+ {% set relation_type = "materialized view" %}
201
+ {%- else -%}
202
+ {%- set relation_type = relation.type -%}
203
+ {%- endif -%}
204
+ comment on {{ relation_type }} {{ relation }} is {{ escaped_comment }};
200
205
  {% endmacro %}
201
206
 
202
207
 
@@ -0,0 +1,20 @@
1
+ {% macro postgres__get_incremental_default_sql(arg_dict) %}
2
+
3
+ {% if arg_dict["unique_key"] %}
4
+ {% do return(get_incremental_delete_insert_sql(arg_dict)) %}
5
+ {% else %}
6
+ {% do return(get_incremental_append_sql(arg_dict)) %}
7
+ {% endif %}
8
+
9
+ {% endmacro %}
10
+
11
+
12
+ {% macro postgres__get_incremental_microbatch_sql(arg_dict) %}
13
+
14
+ {% if arg_dict["unique_key"] %}
15
+ {% do return(adapter.dispatch('get_incremental_merge_sql', 'dbt')(arg_dict)) %}
16
+ {% else %}
17
+ {{ exceptions.raise_compiler_error("dbt-postgres 'microbatch' requires a `unique_key` config") }}
18
+ {% endif %}
19
+
20
+ {% endmacro %}
@@ -2,12 +2,19 @@
2
2
  {% macro postgres__snapshot_merge_sql(target, source, insert_cols) -%}
3
3
  {%- set insert_cols_csv = insert_cols | join(', ') -%}
4
4
 
5
+ {%- set columns = config.get("snapshot_table_column_names") or get_snapshot_table_column_names() -%}
6
+
5
7
  update {{ target }}
6
- set dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to
8
+ set {{ columns.dbt_valid_to }} = DBT_INTERNAL_SOURCE.{{ columns.dbt_valid_to }}
7
9
  from {{ source }} as DBT_INTERNAL_SOURCE
8
- where DBT_INTERNAL_SOURCE.dbt_scd_id::text = {{ target }}.dbt_scd_id::text
10
+ where DBT_INTERNAL_SOURCE.{{ columns.dbt_scd_id }}::text = {{ target }}.{{ columns.dbt_scd_id }}::text
9
11
  and DBT_INTERNAL_SOURCE.dbt_change_type::text in ('update'::text, 'delete'::text)
10
- and {{ target }}.dbt_valid_to is null;
12
+ {% if config.get("dbt_valid_to_current") %}
13
+ and ({{ target }}.{{ columns.dbt_valid_to }} = {{ config.get('dbt_valid_to_current') }} or {{ target }}.{{ columns.dbt_valid_to }} is null);
14
+ {% else %}
15
+ and {{ target }}.{{ columns.dbt_valid_to }} is null;
16
+ {% endif %}
17
+
11
18
 
12
19
  insert into {{ target }} ({{ insert_cols_csv }})
13
20
  select {% for column in insert_cols -%}
@@ -4,7 +4,7 @@ name = "dbt-postgres"
4
4
  description = "The set of adapter protocols and base functionality that supports integration with dbt-core"
5
5
  readme = "README.md"
6
6
  keywords = ["dbt", "adapter", "adapters", "database", "elt", "dbt-core", "dbt Core", "dbt Cloud", "dbt Labs", "postgres"]
7
- requires-python = ">=3.8.0"
7
+ requires-python = ">=3.9.0"
8
8
  authors = [
9
9
  { name = "dbt Labs", email = "info@dbtlabs.com" },
10
10
  ]
@@ -17,21 +17,20 @@ classifiers = [
17
17
  "Operating System :: MacOS :: MacOS X",
18
18
  "Operating System :: Microsoft :: Windows",
19
19
  "Operating System :: POSIX :: Linux",
20
- "Programming Language :: Python :: 3.8",
21
20
  "Programming Language :: Python :: 3.9",
22
21
  "Programming Language :: Python :: 3.10",
23
22
  "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
24
  ]
25
25
  dependencies = [
26
26
  "psycopg2-binary>=2.9,<3.0",
27
- "dbt-adapters>=0.1.0a1,<2.0",
27
+ "dbt-adapters>=1.7.0,<2.0",
28
28
  # add dbt-core to ensure backwards compatibility of installation, this is not a functional dependency
29
- "dbt-core>=1.8.0a1",
29
+ "dbt-core>=1.8.0",
30
30
  # installed via dbt-adapters but used directly
31
- "dbt-common>=0.1.0a1,<2.0",
31
+ "dbt-common>=1.0.4,<2.0",
32
32
  "agate>=1.0,<2.0",
33
33
  ]
34
-
35
34
  [project.urls]
36
35
  Homepage = "https://github.com/dbt-labs/dbt-postgres"
37
36
  Documentation = "https://docs.getdbt.com"
@@ -56,38 +55,30 @@ path = "dbt/adapters/postgres/__version__.py"
56
55
  dependencies = [
57
56
  "dbt-adapters @ git+https://github.com/dbt-labs/dbt-adapters.git",
58
57
  "dbt-common @ git+https://github.com/dbt-labs/dbt-common.git",
59
- 'pre-commit==3.7.0;python_version>="3.9"',
60
- 'pre-commit==3.5.0;python_version=="3.8"',
61
- ]
62
- [tool.hatch.envs.default.scripts]
63
- dev = "pre-commit install"
64
- code-quality = "pre-commit run --all-files"
65
-
66
- [tool.hatch.envs.unit-tests]
67
- dependencies = [
68
- "dbt-adapters @ git+https://github.com/dbt-labs/dbt-adapters.git",
69
- "dbt-common @ git+https://github.com/dbt-labs/dbt-common.git",
58
+ "dbt-tests-adapter @ git+https://github.com/dbt-labs/dbt-adapters.git#subdirectory=dbt-tests-adapter",
70
59
  "dbt-core @ git+https://github.com/dbt-labs/dbt-core.git#subdirectory=core",
60
+ "pre-commit==3.7.0",
71
61
  "freezegun",
72
62
  "pytest",
73
63
  "pytest-dotenv",
74
64
  "pytest-mock",
75
65
  "pytest-xdist",
76
66
  ]
77
- [tool.hatch.envs.unit-tests.scripts]
78
- all = "python -m pytest {args:tests/unit}"
79
-
80
- [tool.hatch.envs.integration-tests]
81
- template = "unit-tests"
82
- extra-dependencies = [
83
- "dbt-tests-adapter @ git+https://github.com/dbt-labs/dbt-adapters.git#subdirectory=dbt-tests-adapter",
84
- ]
85
- [tool.hatch.envs.integration-tests.env-vars]
67
+ [tool.hatch.envs.default.env-vars]
86
68
  DBT_TEST_USER_1 = "dbt_test_user_1"
87
69
  DBT_TEST_USER_2 = "dbt_test_user_2"
88
70
  DBT_TEST_USER_3 = "dbt_test_user_3"
89
- [tool.hatch.envs.integration-tests.scripts]
90
- all = "python -m pytest {args:tests/functional}"
71
+ [tool.hatch.envs.default.scripts]
72
+ setup = "pre-commit install"
73
+ code-quality = "pre-commit run --all-files"
74
+ unit-tests = "python -m pytest {args:tests/unit}"
75
+ integration-tests = "python -m pytest {args:tests/functional}"
76
+ docker-dev = [
77
+ "echo Does not support integration testing, only development and unit testing. See issue https://github.com/dbt-labs/dbt-postgres/issues/99",
78
+ "docker build -f docker/dev.Dockerfile -t dbt-postgres-dev .",
79
+ "docker run --rm -it --name dbt-postgres-dev -v $(pwd):/opt/code dbt-postgres-dev",
80
+ ]
81
+ docker-prod = "docker build -f docker/Dockerfile -t dbt-postgres ."
91
82
 
92
83
  [tool.hatch.envs.build]
93
84
  detached = true
@@ -1 +0,0 @@
1
- version = "1.8.2"
@@ -1,9 +0,0 @@
1
- {% macro postgres__get_incremental_default_sql(arg_dict) %}
2
-
3
- {% if arg_dict["unique_key"] %}
4
- {% do return(get_incremental_delete_insert_sql(arg_dict)) %}
5
- {% else %}
6
- {% do return(get_incremental_append_sql(arg_dict)) %}
7
- {% endif %}
8
-
9
- {% endmacro %}
File without changes
File without changes