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

feat: Activate Version with example test #89

Merged
merged 13 commits into from
Feb 14, 2023
Merged

feat: Activate Version with example test #89

merged 13 commits into from
Feb 14, 2023

Conversation

visch
Copy link
Member

@visch visch commented Jan 23, 2023

Closes #72
Closes #88

@visch visch changed the title Activat Version example test Activate Version example test Jan 23, 2023
| sqlalchemy_url | False | None | SQLAlchemy connection string. This will override using host, user, password, port,dialect. Note that you must esacpe password specialcharacters properly seehttps://docs.sqlalchemy.org/en/20/core/engines.html#escaping-special-characters-such-as-signs-in-passwords |
| dialect+driver | False | postgresql+psycopg2 | Dialect+driver see https://docs.sqlalchemy.org/en/20/core/engines.html. Generally just leave this alone. Note if sqlalchemy_url is set this will be ignored. |
| default_target_schema | False | None | Postgres schema to send data to, example: tap-clickup |
| hard_delete | False | 0 | When activate version is sent from a tap this specefies if we should delete the records that don't match, or mark them with a date in the `_sdc_deleted_at` column. |
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boolean should be generated as True / False here I think? I'll leave for now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Very strange that it shows defaults of 0. Agreed though we don't need to block on this.

@@ -252,3 +255,62 @@ def schema_name(self) -> Optional[str]:

# Schema name not detected.
return None

def activate_version(self, new_version: int) -> None:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could take this function and just drop it into the SDK as it is here, this just has a few tweaks that are needed to make this work in a more generic way

if self.config["hard_delete"] is True:
self.connection.execute(
f"DELETE FROM {self.full_table_name} "
f"WHERE {self.version_column_name} <= {new_version} OR {self.version_column_name} IS NULL"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little worried about what would happen if someone ran this in production with add_record_metadata set to True for a while, then suddenly they change it to False.

I think we'd end up dropping the entire table, because we'd add all the new records, then none of them would have a new_version set they'd all be NULL. Then we'd drop all the NULLs. :O

Removing the IS NULL check would work here but I think the better thing to do would be a check to be sure metadata_columns is enabled as I think the IS NULL check is very valid here as in normal operation you want activate_version to be keeping your data very "clean" and in the same shape as the source.

I should also write a test for this case as it's potentially scary (only place in our code that we drop tables so being cautious is good)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we fix the other issue https://github.com/MeltanoLabs/target-postgres/pull/89/files#r1084618420 I believe this one gets solved as well.

target_postgres/sinks.py Outdated Show resolved Hide resolved
@aaronsteers aaronsteers changed the title Activate Version example test feat: Activate Version with example test Jan 23, 2023
visch and others added 4 commits January 24, 2023 11:03
…of ACTIVATE_VERSION sometimes send an ACTIVATE_MESSAGE before records are sent which I think is just a bad tap implemention but it is valid
Copy link
Member

@edgarrmondragon edgarrmondragon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great so far @visch!

@visch visch marked this pull request as ready for review January 30, 2023 20:03
@visch visch requested a review from edgarrmondragon January 30, 2023 20:03
@visch visch self-assigned this Feb 3, 2023
| sqlalchemy_url | False | None | SQLAlchemy connection string. This will override using host, user, password, port,dialect. Note that you must esacpe password specialcharacters properly seehttps://docs.sqlalchemy.org/en/20/core/engines.html#escaping-special-characters-such-as-signs-in-passwords |
| dialect+driver | False | postgresql+psycopg2 | Dialect+driver see https://docs.sqlalchemy.org/en/20/core/engines.html. Generally just leave this alone. Note if sqlalchemy_url is set this will be ignored. |
| default_target_schema | False | None | Postgres schema to send data to, example: tap-clickup |
| hard_delete | False | 0 | When activate version is sent from a tap this specefies if we should delete the records that don't match, or mark them with a date in the `_sdc_deleted_at` column. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Very strange that it shows defaults of 0. Agreed though we don't need to block on this.

README.md Outdated Show resolved Hide resolved
target_postgres/sinks.py Show resolved Hide resolved
Co-authored-by: Aaron ("AJ") Steers <aj@meltano.com>
@visch visch merged commit 8150737 into main Feb 14, 2023
@visch visch deleted the activate_version branch February 14, 2023 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add sdc_metadata to records Support for activate version
3 participants