Skip to content

Commit

Permalink
updated campaigns state migration
Browse files Browse the repository at this point in the history
  • Loading branch information
darynaishchenko committed Feb 18, 2025
1 parent 863c87c commit 7d319fb
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
from airbyte_cdk.sources.types import Config


ARCHIVED_SMS = {"archived": "true", "campaign_type": "sms"}
NOT_ARCHIVED_SMS = {"archived": "false", "campaign_type": "sms"}
ARCHIVED_EMAIL = {"archived": "true", "campaign_type": "email"}
NOT_ARCHIVED_EMAIL = {"archived": "false", "campaign_type": "email"}

Expand Down Expand Up @@ -84,6 +82,7 @@ def migrate(self, stream_state: Mapping[str, Any]) -> Mapping[str, Any]:
class CampaignsStateMigration(ArchivedToPerPartitionStateMigration):
"""
Campaigns stream has 2 partition field: archived and campaign_type(email, sms).
Previous API version didn't return sms in campaigns output so we need to migrate only email partition.
Example input state:
{
Expand All @@ -93,18 +92,10 @@ class CampaignsStateMigration(ArchivedToPerPartitionStateMigration):
}
}
Example output state:
{
"partition":{ "archived":"true","campaign_type":"sms" },
"cursor":{ "updated_at":"2021-10-10T00:00:00+00:00" }
}
{
"partition":{ "archived":"true","campaign_type":"email" },
"cursor":{ "updated_at":"2021-10-10T00:00:00+00:00" }
}
{
"partition":{ "archived":"false","campaign_type":"sms" },
"cursor":{ "updated_at":"2020-10-10T00:00:00+00:00" }
}
{
"partition":{ "archived":"false","campaign_type":"email" },
"cursor":{ "updated_at":"2020-10-10T00:00:00+00:00" }
Expand All @@ -119,8 +110,6 @@ def migrate(self, stream_state: Mapping[str, Any]) -> Mapping[str, Any]:

migrated_stream_state = {
"states": [
{"partition": ARCHIVED_SMS, "cursor": {self._cursor.cursor_field: is_archived_updated_at}},
{"partition": NOT_ARCHIVED_SMS, "cursor": {self._cursor.cursor_field: is_not_archived_updated_at}},
{"partition": ARCHIVED_EMAIL, "cursor": {self._cursor.cursor_field: is_archived_updated_at}},
{"partition": NOT_ARCHIVED_EMAIL, "cursor": {self._cursor.cursor_field: is_not_archived_updated_at}},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ def test_migrate(state, expected_state):
{"updated_at": "2120-10-10T00:00:00+00:00", "archived": {"updated_at": "2020-10-10T00:00:00+00:00"}},
{
"states": [
{"cursor": {"updated_at": "2020-10-10T00:00:00+00:00"}, "partition": {"archived": "true", "campaign_type": "sms"}},
{"cursor": {"updated_at": "2120-10-10T00:00:00+00:00"}, "partition": {"archived": "false", "campaign_type": "sms"}},
{"cursor": {"updated_at": "2020-10-10T00:00:00+00:00"}, "partition": {"archived": "true", "campaign_type": "email"}},
{"cursor": {"updated_at": "2120-10-10T00:00:00+00:00"}, "partition": {"archived": "false", "campaign_type": "email"}},
]
Expand All @@ -93,8 +91,6 @@ def test_migrate(state, expected_state):
{"archived": {"updated_at": "2020-10-10T00:00:00+00:00"}},
{
"states": [
{"cursor": {"updated_at": "2020-10-10T00:00:00+00:00"}, "partition": {"archived": "true", "campaign_type": "sms"}},
{"cursor": {"updated_at": "2012-01-01T00:00:00Z"}, "partition": {"archived": "false", "campaign_type": "sms"}},
{"cursor": {"updated_at": "2020-10-10T00:00:00+00:00"}, "partition": {"archived": "true", "campaign_type": "email"}},
{"cursor": {"updated_at": "2012-01-01T00:00:00Z"}, "partition": {"archived": "false", "campaign_type": "email"}},
]
Expand All @@ -106,8 +102,6 @@ def test_migrate(state, expected_state):
},
{
"states": [
{"cursor": {"updated_at": "2012-01-01T00:00:00Z"}, "partition": {"archived": "true", "campaign_type": "sms"}},
{"cursor": {"updated_at": "2120-10-10T00:00:00+00:00"}, "partition": {"archived": "false", "campaign_type": "sms"}},
{"cursor": {"updated_at": "2012-01-01T00:00:00Z"}, "partition": {"archived": "true", "campaign_type": "email"}},
{"cursor": {"updated_at": "2120-10-10T00:00:00+00:00"}, "partition": {"archived": "false", "campaign_type": "email"}},
]
Expand Down

0 comments on commit 7d319fb

Please sign in to comment.