Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into config/docker-release
Browse files Browse the repository at this point in the history
# Conflicts:
#	dbt/adapters/postgres/relation.py
#	pyproject.toml
#	tests/unit/test_renamed_relations.py
  • Loading branch information
mikealfare committed Apr 26, 2024
2 parents 45952e7 + cf10056 commit 0d0a074
Show file tree
Hide file tree
Showing 38 changed files with 284 additions and 1,002 deletions.
9 changes: 9 additions & 0 deletions .changes/1.0.8-b3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## dbt-postgres 1.0.8-b3 - April 16, 2024

### Fixes

* Determine `psycopg2` based on `platform_system` (Linux or other), remove usage of `DBT_PSYCOPG2_NAME` environment variable

### Under the Hood

* Update dependabot configuration to cover GHA
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20240323-160222.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Debug log when `type_code` fails to convert to a `data_type`
time: 2024-03-23T16:02:22.153674-06:00
custom:
Author: dbeatty10
Issue: "8912"
6 changes: 0 additions & 6 deletions .changes/unreleased/Fixes-20240412-153154.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240423-180916.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: remove materialized views from renambeable relation and remove a quote
time: 2024-04-23T18:09:16.865258-05:00
custom:
Author: McKnight-42
Issue: "127"
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240425-133401.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Replace usage of `Set` with `List` to fix issue with index updates intermittently happening out of order
time: 2024-04-25T13:34:01.018399-04:00
custom:
Author: mikealfare
Issue: "72"
6 changes: 0 additions & 6 deletions .changes/unreleased/Under the Hood-20240410-180644.yaml

This file was deleted.

28 changes: 9 additions & 19 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ on:
workflow_dispatch:
inputs:
dbt_adapters_branch:
description: "The branch of dbt-adapters to evaluate"
type: string
required: true
default: "main"
description: "The branch of dbt-adapters to evaluate"
type: string
default: "main"
workflow_call:
inputs:
dbt_adapters_branch:
description: "The branch of dbt-adapters to evaluate"
type: string
required: true
default: "main"

permissions: read-all
Expand All @@ -27,34 +25,26 @@ permissions: read-all
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ contains(github.event_name, 'pull_request') && github.event.pull_request.head.ref || github.sha }}
cancel-in-progress: true
env:
# set DBT_ADAPTERS_BRANCH to the input value if the event is a workflow_dispatch (workflow_call uses the same event_name),
# otherwise use 'main'
DBT_ADAPTERS_BRANCH: ${{ github.event_name == 'workflow_dispatch' && inputs.dbt_adapters_branch || 'main' }}

jobs:
code-quality:
name: Code Quality
runs-on: ubuntu-latest


steps:
- name: Check out repository
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Update Adapters and Core branches
if: ${{ contains(github.event_name, 'workflow_') }}
shell: bash
run: |
./.github/scripts/update_dev_packages.sh \
$DBT_ADAPTERS_BRANCH \
"main"
run: ./.github/scripts/update_dev_packages.sh ${{ inputs.dbt_adapters_branch }} "main"

- name: Setup `hatch`
uses: dbt-labs/dbt-adapters/.github/actions/setup-hatch@main

- name: Run linters
run: hatch run lint:all

- name: Run typechecks
run: hatch run typecheck:all
- name: Run code quality
shell: bash
run: hatch run code-quality
11 changes: 1 addition & 10 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ on:
required: false
default: "main"


permissions: read-all

# will cancel previous workflows triggered by the same event and for the same ref for PRs or same SHA otherwise
Expand Down Expand Up @@ -101,14 +100,6 @@ jobs:
POSTGRES_TEST_DATABASE: dbt
POSTGRES_TEST_THREADS: 4

- name: Publish results
uses: dbt-labs/dbt-adapters/.github/actions/publish-results@main
if: always()
with:
source-file: "results.csv"
file-name: "integration_results"
python-version: ${{ matrix.python-version }}

psycopg2-check:
name: "Test psycopg2 build version"
runs-on: ${{ matrix.scenario.platform }}
Expand All @@ -117,7 +108,7 @@ jobs:
matrix:
scenario:
- {platform: ubuntu-latest, psycopg2-name: psycopg2}
- {platform: macos-latest, psycopg2-name: psycopg2-binary}
- {platform: macos-12, psycopg2-name: psycopg2-binary}
steps:
- name: "Check out repository"
uses: actions/checkout@v4
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,3 @@ jobs:
- name: Run unit tests
run: hatch run unit-tests:all
shell: bash

- name: Publish results
uses: dbt-labs/dbt-adapters/.github/actions/publish-results@main
if: always()
with:
source-file: "results.csv"
file-name: "unit_results"
python-version: ${{ matrix.python-version }}
55 changes: 55 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
default_language_version:
python: python3

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
args: [--unsafe]
- id: check-json
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-case-conflict

- repo: https://github.com/dbt-labs/pre-commit-hooks
rev: v0.1.0a1
hooks:
- id: dbt-core-in-adapters-check

- repo: https://github.com/psf/black
rev: 24.4.0
hooks:
- id: black
args:
- --line-length=99
- --target-version=py38
- --target-version=py39
- --target-version=py310
- --target-version=py311

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
exclude: tests/
args:
- --max-line-length=99
- --select=E,F,W
- --ignore=E203,E501,E741,W503,W504
- --per-file-ignores=*/__init__.py:F401

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
args:
- --explicit-package-bases
- --ignore-missing-imports
- --pretty
- --show-error-codes
files: ^dbt/adapters/postgres
additional_dependencies:
- types-PyYAML
- types-protobuf
- types-pytz
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ and is generated by [Changie](https://github.com/miniscruff/changie).
### Security

* Pin `black>=24.3` in `pyproject.toml`

## dbt-postgres 1.0.8-b3 - April 16, 2024

### Fixes

* Determine `psycopg2` based on `platform_system` (Linux or other), remove usage of `DBT_PSYCOPG2_NAME` environment variable

### Under the Hood

* Update dependabot configuration to cover GHA
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Remember to commit and push the file that's created.

### Signing the CLA

> **_NOTE:_** All contributors to `dbt-postgres` must sign the
> **_NOTE:_** All contributors to `dbt-postgres` must sign the
> [Contributor License Agreement](https://docs.getdbt.com/docs/contributor-license-agreements)(CLA).
Maintainers will be unable to merge contributions until the contributor signs the CLA.
Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/postgres/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.8.0b2"
version = "1.8.0b4"
3 changes: 3 additions & 0 deletions dbt/adapters/postgres/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

from dbt.adapters.contracts.connection import AdapterResponse, Credentials
from dbt.adapters.events.logging import AdapterLogger
from dbt.adapters.events.types import TypeCodeNotFound
from dbt.adapters.sql import SQLConnectionManager
from dbt_common.exceptions import DbtDatabaseError, DbtRuntimeError
from dbt_common.events.functions import warn_or_error
from dbt_common.helper_types import Port
from mashumaro.jsonschema.annotations import Maximum, Minimum
import psycopg2
Expand Down Expand Up @@ -203,4 +205,5 @@ def data_type_code_to_name(cls, type_code: Union[int, str]) -> str:
if type_code in psycopg2.extensions.string_types:
return psycopg2.extensions.string_types[type_code].name
else:
warn_or_error(TypeCodeNotFound(type_code=type_code))
return f"unknown type_code {type_code}"
21 changes: 12 additions & 9 deletions dbt/adapters/postgres/relation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass, field
from typing import FrozenSet, Optional, Set
from typing import FrozenSet, List, Optional

from dbt.adapters.base.relation import BaseRelation
from dbt.adapters.contracts.relation import RelationConfig, RelationType
Expand All @@ -25,7 +25,6 @@ class PostgresRelation(BaseRelation):
{
RelationType.View,
RelationType.Table,
RelationType.MaterializedView,
}
)
)
Expand Down Expand Up @@ -80,7 +79,7 @@ def _get_index_config_changes(
self,
existing_indexes: FrozenSet[PostgresIndexConfig],
new_indexes: FrozenSet[PostgresIndexConfig],
) -> Set[PostgresIndexConfigChange]:
) -> List[PostgresIndexConfigChange]:
"""
Get the index updates that will occur as a result of a new run
Expand All @@ -91,18 +90,22 @@ def _get_index_config_changes(
3. Index is old -> drop these
4. Indexes are not equal -> drop old, create new -> two actions
Returns: a set of index updates in the form {"action": "drop/create", "context": <IndexConfig>}
*Note:*
The order of the operations matters here because if the same index is dropped and recreated
(e.g. via --full-refresh) then we need to drop it first, then create it.
Returns: an ordered list of index updates in the form {"action": "drop/create", "context": <IndexConfig>}
"""
drop_changes = set(
drop_changes = [
PostgresIndexConfigChange.from_dict(
{"action": RelationConfigChangeAction.drop, "context": index}
)
for index in existing_indexes.difference(new_indexes)
)
create_changes = set(
]
create_changes = [
PostgresIndexConfigChange.from_dict(
{"action": RelationConfigChangeAction.create, "context": index}
)
for index in new_indexes.difference(existing_indexes)
)
return set().union(drop_changes, create_changes) # type: ignore
]
return drop_changes + create_changes
2 changes: 1 addition & 1 deletion dbt/adapters/postgres/relation_configs/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PostgresIndexMethod(StrEnum):

@classmethod
def default(cls) -> "PostgresIndexMethod":
return cls.btree
return cls("btree")


@dataclass(frozen=True, eq=True, unsafe_hash=True)
Expand Down
4 changes: 2 additions & 2 deletions dbt/adapters/postgres/relation_configs/materialized_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ def parse_relation_results(cls, relation_results: RelationResults) -> dict:

@dataclass
class PostgresMaterializedViewConfigChangeCollection:
indexes: Set[PostgresIndexConfigChange] = field(default_factory=set)
indexes: List[PostgresIndexConfigChange] = field(default_factory=list)

@property
def requires_full_refresh(self) -> bool:
return any(index.requires_full_refresh for index in self.indexes)

@property
def has_changes(self) -> bool:
return self.indexes != set()
return self.indexes != []
2 changes: 1 addition & 1 deletion dbt/include/postgres/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
on {{ relation }} {% if index_config.type -%}
using {{ index_config.type }}
{%- endif %}
({{ comma_separated_columns }});
({{ comma_separated_columns }})
{%- endmacro %}

{% macro postgres__create_schema(relation) -%}
Expand Down
Loading

0 comments on commit 0d0a074

Please sign in to comment.