-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Redshift parameter to create tables with backup option specified (…
…#42) * Update impl and adapters to support backup parameter * Add test files * Add test files * Add PR link to Changelog * Add EOF newlines * Debug and split test into two separate cases * Add contributor info Co-authored-by: Jeremy Cohen <[email protected]>
- Loading branch information
Showing
8 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
tests/integration/backup_table_tests/models/model_backup_false.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{{ | ||
config( | ||
materialized='table', backup=False | ||
) | ||
}} | ||
|
||
select 1 |
7 changes: 7 additions & 0 deletions
7
tests/integration/backup_table_tests/models/model_backup_true.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{{ | ||
config( | ||
materialized='table', backup=True | ||
) | ||
}} | ||
|
||
select 2 |
7 changes: 7 additions & 0 deletions
7
tests/integration/backup_table_tests/models/model_backup_true_view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{{ | ||
config( | ||
materialized='view', backup=True | ||
) | ||
}} | ||
|
||
select 3 |
7 changes: 7 additions & 0 deletions
7
tests/integration/backup_table_tests/models/model_backup_undefined.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
90
tests/integration/backup_table_tests/test_backup_table_option.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |