Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using string interpoloation to gather correct pointer for dbt-core te… #80

Merged
merged 29 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ea1c4b6
Merge `main` into `1.0.latest` (#46)
leahwicz Dec 3, 2021
ffce642
[Backport] Bumping version to 1.0.0 (#47) (#48)
leahwicz Dec 3, 2021
58efd83
Fix package version (#49)
leahwicz Dec 3, 2021
5571085
using string interpoloation to gather correct pointer for dbt-core te…
McKnight-42 Mar 11, 2022
c318e41
created new job for gha to grab correct version of dbt-core to test b…
McKnight-42 Mar 11, 2022
d1a04d0
minor update
McKnight-42 Mar 11, 2022
5a50ae5
Merge branch 'main' into mcknight/fix_gha_for_adapter_releases
McKnight-42 Mar 11, 2022
f21bc6f
adding Get dbt-core-version step to integration.yaml
McKnight-42 Mar 11, 2022
fea3667
Merge branch 'mcknight/fix_gha_for_adapter_releases' of gist.github.c…
McKnight-42 Mar 11, 2022
bac8f96
modifying version parameters
McKnight-42 Mar 14, 2022
7886109
change for integration testing
McKnight-42 Mar 14, 2022
d54ef1d
updating file
McKnight-42 Mar 14, 2022
b6afaa5
readding pull_request_target now that tests pass
McKnight-42 Mar 14, 2022
95af266
make nit: suggested changes
McKnight-42 Mar 18, 2022
fc3163a
testing conditional logic in integration.yml
McKnight-42 Mar 18, 2022
e06d067
updating test names
McKnight-42 Mar 18, 2022
eb12449
creating main.yml versions of new condtional steps for dbt-version ga…
McKnight-42 Mar 18, 2022
64847f0
trying different version of test v.2
McKnight-42 Mar 18, 2022
dade718
v.3 of conditional mix of original version of tests and leah logic
McKnight-42 Mar 18, 2022
b5c38ea
adding comment and changelog entry
McKnight-42 Mar 18, 2022
bfe69d7
changes made after review by @VersusFacit and @Kwigley
McKnight-42 Mar 19, 2022
d19a374
name change
McKnight-42 Mar 19, 2022
31d0b71
minor updates
McKnight-42 Mar 21, 2022
bd7f2ac
updating name of version ref
McKnight-42 Mar 21, 2022
c902a60
name change of dbt-version step to dbt-core-ref to be more descriptiv…
McKnight-42 Mar 21, 2022
ba7531a
Update test_backup_table_option.py
McKnight-42 Mar 21, 2022
f1e3732
Update test_backup_table_option.py
McKnight-42 Mar 21, 2022
698ac86
reseting file that shouldn't of been changed
McKnight-42 Mar 21, 2022
b1b72ba
Merge branch 'mcknight/fix_gha_for_adapter_releases' of gist.github.c…
McKnight-42 Mar 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.0rc1
current_version = 1.0.0
parse = (?P<major>\d+)
\.(?P<minor>\d+)
\.(?P<patch>\d+)
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,19 @@ jobs:
"You do not have permissions to run integration tests, @dbt-labs/core "\
"needs to label this PR with `ok to test` in order to run integration tests!"
check_for_duplicate_msg: true

slack-results:
runs-on: ubuntu-latest
needs: test
if: always()

McKnight-42 marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: Posting scheduled run failures
uses: ravsamhq/notify-slack-action@v1
if: ${{ github.event_name == 'schedule' }}
with:
notification_title: 'Redshift nightly integration test failed'
status: ${{ job.status }}
notify_when: 'failure'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DEV_CORE_ALERTS }}
17 changes: 12 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,28 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Get dbt-core version
id: dbt-core-version
run: |
echo "::set-output name=dbt-version::${{
( contains( github.event.pull_request.base.ref, 'latest' ) || github.event.pull_request.base.ref == main)
&& github.event.pull_request.base.ref
|| main
McKnight-42 marked this conversation as resolved.
Show resolved Hide resolved
}}"
- name: Install python dependencies
run: |
pip install --user --upgrade pip
pip install tox
pip --version
tox --version

- name: Install dbt-core latest
- name: Install dbt-core from branch ${{ steps.dbt-core-version.outputs.dbt-version }}
McKnight-42 marked this conversation as resolved.
Show resolved Hide resolved
run: |
pip install "git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core"
pip install "git+https://github.com/dbt-labs/dbt-core.git@${{ steps.dbt-core-version.outputs.dbt-version }}#egg=dbt-core&subdirectory=core"

- name: Install dbt-postgres latest
- name: Install dbt-postgres from ${{ steps.dbt-core-version.outputs.dbt-version }}
run: |
pip install "git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-postgres&subdirectory=plugins/postgres"
pip install "git+https://github.com/dbt-labs/dbt-core.git@${{ steps.dbt-core-version.outputs.dbt-version }}#egg=dbt-postgres&subdirectory=plugins/postgres"

- name: Run tox
run: tox
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
## dbt-redshift 1.0.0 (Release TBD)
## dbt-redshift 1.0.0 (December 3, 2021)

## dbt-redshift 1.0.0rc2 (November 24, 2021)

### Under the hood
- Add optional Redshift parameter to create tables with BACKUP NO set, to exclude them from snapshots. ([#18](https://github.com/dbt-labs/dbt-redshift/issues/18), [#42](https://github.com/dbt-labs/dbt-redshift/pull/42))

### Contributors
- [@dlb8685](https://github.com/dlb8685) ([#42](https://github.com/dbt-labs/dbt-redshift/pull/42))

## dbt-redshift 1.0.0rc1 (November 10, 2021)

Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/redshift/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '1.0.0rc1'
version = '1.0.0'
1 change: 1 addition & 0 deletions dbt/adapters/redshift/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class RedshiftConfig(AdapterConfig):
dist: Optional[str] = None
sort: Optional[str] = None
bind: Optional[bool] = None
backup: Optional[bool] = True


class RedshiftAdapter(PostgresAdapter, SQLAdapter):
Expand Down
2 changes: 2 additions & 0 deletions dbt/include/redshift/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
'sort',
validator=validation.any[list, basestring]) -%}
{%- set sql_header = config.get('sql_header', none) -%}
{%- set backup = config.get('backup') -%}

{{ sql_header if sql_header is not none }}

create {% if temporary -%}temporary{%- endif %} table
{{ relation.include(database=(not temporary), schema=(not temporary)) }}
{{ dist(_dist) }}
{{ sort(_sort_type, _sort) }}
{% if backup == false -%}backup no{%- endif %}
as (
{{ sql }}
);
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def _get_dbt_core_version():
pre = (parts["prekind"]+"1" if parts["prekind"] else "")
return f"{minor}{pre}"


#TODO remove old logic and add to versionBump script
McKnight-42 marked this conversation as resolved.
Show resolved Hide resolved
package_name = "dbt-redshift"
package_version = _get_plugin_version()
package_version = "1.0.0"
dbt_core_version = _get_dbt_core_version()
description = """The Redshift adapter plugin for dbt"""

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{
config(
materialized='table', backup=False
)
}}

select 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{
config(
materialized='table', backup=True
)
}}

select 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{
config(
materialized='view', backup=True
)
}}

select 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{
config(
materialized='table'
)
}}

select 4
90 changes: 90 additions & 0 deletions tests/integration/backup_table_tests/test_backup_table_option.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import os

from tests.integration.base import DBTIntegrationTest, use_profile


class TestBackupTableOption(DBTIntegrationTest):
@property
def schema(self):
return 'backup_table_tests'

@staticmethod
def dir(path):
return os.path.normpath(path)

@property
def models(self):
return self.dir("models")

@property
def project_config(self):
return {
'config-version': 2
}

def check_backup_param_template(self, test_table_name, backup_is_expected):
# Use raw DDL statement to confirm backup is set correctly on new table
with open('target/run/test/models/{}.sql'.format(test_table_name), 'r') as ddl_file:
ddl_statement = ddl_file.readlines()
self.assertEqual('backup no' not in ' '.join(ddl_statement).lower(), backup_is_expected)

@use_profile('redshift')
def test__redshift_backup_table_option(self):
self.assertEqual(len(self.run_dbt()), 4)

# model_backup_undefined should not contain a BACKUP NO parameter in the table DDL
self.check_backup_param_template('model_backup_undefined', True)

# model_backup_true should not contain a BACKUP NO parameter in the table DDL
self.check_backup_param_template('model_backup_true', True)

# model_backup_false should contain a BACKUP NO parameter in the table DDL
self.check_backup_param_template('model_backup_false', False)

# Any view should not contain a BACKUP NO parameter, regardless of the specified config (create will fail)
self.check_backup_param_template('model_backup_true_view', True)


class TestBackupTableOptionProjectFalse(DBTIntegrationTest):
@property
def schema(self):
return 'backup_table_tests'

@staticmethod
def dir(path):
return os.path.normpath(path)

@property
def models(self):
return self.dir("models")

@property
def project_config(self):
# Update project config to set backup to False.
# This should make the 'model_backup_undefined' switch to BACKUP NO
return {
'config-version': 2,
'models': {'backup': False}
}

def check_backup_param_template(self, test_table_name, backup_is_expected):
# Use raw DDL statement to confirm backup is set correctly on new table
with open('target/run/test/models/{}.sql'.format(test_table_name), 'r') as ddl_file:
ddl_statement = ddl_file.readlines()
self.assertEqual('backup no' not in ' '.join(ddl_statement).lower(), backup_is_expected)

@use_profile('redshift')
def test__redshift_backup_table_option_project_config_false(self):
self.assertEqual(len(self.run_dbt()), 4)

# model_backup_undefined should contain a BACKUP NO parameter in the table DDL
self.check_backup_param_template('model_backup_undefined', False)

# model_backup_true should not contain a BACKUP NO parameter in the table DDL
self.check_backup_param_template('model_backup_true', True)

# model_backup_false should contain a BACKUP NO parameter in the table DDL
self.check_backup_param_template('model_backup_false', False)

# Any view should not contain a BACKUP NO parameter, regardless of the specified config (create will fail)
self.check_backup_param_template('model_backup_true_view', True)