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

Merge main into 1.0.latest #46

Merged
merged 3 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.0rc2
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()

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 }}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## dbt-redshift 1.0.0 (Release TBD)

## 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)

### Under the hood
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.0rc2'
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
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)