Skip to content

Commit

Permalink
add manual workaround and associated test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare committed Jun 7, 2024
1 parent 1ffb3cb commit b0d5553
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
34 changes: 28 additions & 6 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,21 @@ jobs:
strategy:
fail-fast: false
matrix:
platform:
- ubuntu-24.04
- macos-12
platform: [ubuntu-24.04, macos-12]
python-version: ["3.8", "3.11"]
steps:
- name: "Check out repository"
uses: actions/checkout@v4

- name: Setup `hatch`
uses: dbt-labs/dbt-adapters/.github/actions/setup-hatch@main
with:
python-version: ${{ matrix.python-version }}

- name: "Test psycopg2 name - default"
run: |
hatch env prune
PSYCOPG2_NAME=$(hatch run pip show psycopg2 || pip show psycopg2-binary | grep Name | cut -d " " -f 2)
PSYCOPG2_NAME=$(hatch run pip show psycopg2 || hatch run pip show psycopg2-binary | grep Name | cut -d " " -f 2)
if [[ "$PSYCOPG2_NAME" != "$PSYCOPG2_EXPECTED_NAME" ]]; then
exit 1
Expand All @@ -127,7 +131,7 @@ jobs:
- name: "Test psycopg2 name - invalid override"
run: |
hatch env prune
PSYCOPG2_NAME=$(hatch run pip show psycopg2 || pip show psycopg2-binary | grep Name | cut -d " " -f 2)
PSYCOPG2_NAME=$(hatch run pip show psycopg2 || hatch run pip show psycopg2-binary | grep Name | cut -d " " -f 2)
if [[ "$PSYCOPG2_NAME" != "$PSYCOPG2_EXPECTED_NAME" ]]; then
exit 1
Expand All @@ -139,11 +143,29 @@ jobs:
- name: "Test psycopg2 name - override"
run: |
hatch env prune
PSYCOPG2_NAME=$(hatch run pip show psycopg2 || pip show psycopg2-binary | grep Name | cut -d " " -f 2)
PSYCOPG2_NAME=$(hatch run pip show psycopg2 || hatch run pip show psycopg2-binary | grep Name | cut -d " " -f 2)
if [[ "$PSYCOPG2_NAME" != "$PSYCOPG2_EXPECTED_NAME" ]]; then
exit 1
fi
env:
DBT_PSYCOPG2_NAME: psycopg2
PSYCOPG2_EXPECTED_NAME: psycopg2-binary # this is not yet implemented

- name: "Test psycopg2 name - manual override"
run: |
hatch env prune
# this is the work around
PSYCOPG2_VERSION = $(hatch run pip show psycopg2-binary | grep Version | cut -d " " -f 2)
hatch run pip uninstall -y psycopg2-binary
hatch run pip install psycopg2==$PSYCOPG2_VERSION
# this is the end of the work around
PSYCOPG2_NAME=$(hatch run pip show psycopg2 || hatch run pip show psycopg2-binary | grep Name | cut -d " " -f 2)
if [[ "$PSYCOPG2_NAME" != "$PSYCOPG2_EXPECTED_NAME" ]]; then
exit 1
fi
env:
PSYCOPG2_EXPECTED_NAME: psycopg2
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ more information on using dbt with Postgres, consult [the docs](https://docs.get
- [Install dbt](https://docs.getdbt.com/docs/installation)
- Read the [introduction](https://docs.getdbt.com/docs/introduction/) and [viewpoint](https://docs.getdbt.com/docs/about/viewpoint/)

### `psycopg2-binary` vs. `psycopg2`

By default, `dbt-postgres` installs `psycopg2-binary`. This is great for development, and even testing, as it does not require any OS dependencies; it's a pre-built wheel. However, building `psycopg2` from source will grant performance improvements that are desired in a production environment. In order to install `psycopg2`, use the following steps:

```bash
PSYCOPG2_VERSION = $(pip show psycopg2-binary | grep Version | cut -d " " -f 2)
pip uninstall -y psycopg2-binary
pip install psycopg2==$PSYCOPG2_VERSION
```

This ensures the version of `psycopg2` will match that of `psycopg2-binary`.

## Join the dbt Community

- Be part of the conversation in the [dbt Community Slack](http://community.getdbt.com/)
Expand Down

0 comments on commit b0d5553

Please sign in to comment.