Skip to content

Commit

Permalink
fix: Double quote identifiers when handling activate version (#166)
Browse files Browse the repository at this point in the history
fixes #165

---------

Co-authored-by: Edgar R. M <[email protected]>
  • Loading branch information
andyoneal and edgarrmondragon authored Aug 10, 2023
1 parent ed4703b commit b6350b3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions target_postgres/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def activate_version(self, new_version: int) -> None:
self.logger.info("Hard delete: %s", self.config.get("hard_delete"))
if self.config["hard_delete"] is True:
self.connection.execute(
f"DELETE FROM {self.full_table_name} "
f'DELETE FROM "{self.schema_name}"."{self.table_name}" '
f"WHERE {self.version_column_name} <= {new_version} "
f"OR {self.version_column_name} IS NULL"
)
Expand All @@ -355,7 +355,7 @@ def activate_version(self, new_version: int) -> None:
)
# Need to deal with the case where data doesn't exist for the version column
query = sqlalchemy.text(
f"UPDATE {self.full_table_name}\n"
f'UPDATE "{self.schema_name}"."{self.table_name}"\n'
f"SET {self.soft_delete_column_name} = :deletedate \n"
f"WHERE {self.version_column_name} < :version "
f"OR {self.version_column_name} IS NULL \n"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{"type": "SCHEMA", "stream": "Account", "schema": {"type": "object", "properties": {"Code": {"type": ["string"]}, "Name": {"type": ["null", "string"]}}}, "key_properties": ["Code"], "bookmark_properties": []}
{"type": "ACTIVATE_VERSION", "stream": "Account", "version": 1674486431563}
{"type": "RECORD", "stream": "Account", "record": {"Code": "AF", "Name": "Africa"}, "version": 1674486431563, "time_extracted": "2023-01-23T15:07:11.563063Z"}
{"type": "RECORD", "stream": "Account", "record": {"Code": "AN", "Name": "Antarctica"}, "version": 1674486431563, "time_extracted": "2023-01-23T15:07:11.563063Z"}
{"type": "RECORD", "stream": "Account", "record": {"Code": "AS", "Name": "Asia"}, "version": 1674486431563, "time_extracted": "2023-01-23T15:07:11.563063Z"}
{"type": "RECORD", "stream": "Account", "record": {"Code": "EU", "Name": "Europe"}, "version": 1674486431563, "time_extracted": "2023-01-23T15:07:11.563063Z"}
{"type": "RECORD", "stream": "Account", "record": {"Code": "NA", "Name": "North America"}, "version": 1674486431563, "time_extracted": "2023-01-23T15:07:11.563063Z"}
{"type": "RECORD", "stream": "Account", "record": {"Code": "OC", "Name": "Oceania"}, "version": 1674486431563, "time_extracted": "2023-01-23T15:07:11.563063Z"}
{"type": "RECORD", "stream": "Account", "record": {"Code": "SA", "Name": "South America"}, "version": 1674486431563, "time_extracted": "2023-01-23T15:07:11.563063Z"}
{"type": "ACTIVATE_VERSION", "stream": "Account", "version": 1674486431563}
9 changes: 9 additions & 0 deletions target_postgres/tests/test_standard_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,15 @@ def test_uppercase_stream_name_with_column_alter(postgres_target):
singer_file_to_target(file_name, postgres_target)


def test_activate_version_uppercase_stream_name(postgres_config_no_ssl):
"""Activate Version should work with uppercase stream names"""
file_name = "test_activate_version_uppercase_stream_name.singer"
postgres_config_hard_delete = copy.deepcopy(postgres_config_no_ssl)
postgres_config_hard_delete["hard_delete"] = True
pg_hard_delete = TargetPostgres(config=postgres_config_hard_delete)
singer_file_to_target(file_name, pg_hard_delete)


def test_postgres_ssl_no_config(postgres_config_no_ssl):
"""Test that connection will fail when no SSL configuration options are provided.
Expand Down

0 comments on commit b6350b3

Please sign in to comment.