-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migrate given project's (edge) identities to environments v2 (#…
…3138) Co-authored-by: Matthew Elwell <[email protected]>
- Loading branch information
1 parent
44ee410
commit 574a08e
Showing
17 changed files
with
453 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
ENVIRONMENTS_V2_PARTITION_KEY = "environment_id" | ||
ENVIRONMENTS_V2_SORT_KEY = "document_key" | ||
|
||
ENVIRONMENTS_V2_ENVIRONMENT_META_DOCUMENT_KEY = "_META" | ||
|
||
ENVIRONMENTS_V2_SECONDARY_INDEX = "environment_api_key-index" | ||
ENVIRONMENTS_V2_SECONDARY_INDEX_PARTITION_KEY = "environment_api_key" | ||
|
||
IDENTITIES_PAGINATION_LIMIT = 1000 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import logging | ||
from typing import Generator, Iterable | ||
|
||
from environments.dynamodb.dynamodb_wrapper import ( | ||
DynamoEnvironmentV2Wrapper, | ||
DynamoIdentityWrapper, | ||
) | ||
from environments.dynamodb.types import ( | ||
IdentityOverridesV2Changeset, | ||
IdentityOverrideV2, | ||
) | ||
from environments.models import Environment | ||
from util.mappers import map_engine_feature_state_to_identity_override | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def migrate_environments_to_v2(project_id: int) -> None: | ||
dynamo_wrapper_v2 = DynamoEnvironmentV2Wrapper() | ||
identity_wrapper = DynamoIdentityWrapper() | ||
|
||
if not (dynamo_wrapper_v2.is_enabled and identity_wrapper.is_enabled): | ||
return | ||
|
||
logger.info("Migrating environments to v2 for project %d", project_id) | ||
|
||
environments_to_migrate = Environment.objects.filter(project_id=project_id) | ||
identity_overrides_to_migrate = _iter_paginated_overrides( | ||
identity_wrapper=identity_wrapper, | ||
environments=environments_to_migrate, | ||
) | ||
|
||
changeset = IdentityOverridesV2Changeset( | ||
to_put=list(identity_overrides_to_migrate), to_delete=[] | ||
) | ||
logger.info( | ||
"Retrieved %d identity overrides to migrate for project %d", | ||
len(changeset.to_put), | ||
project_id, | ||
) | ||
|
||
dynamo_wrapper_v2.write_environments(environments_to_migrate) | ||
dynamo_wrapper_v2.update_identity_overrides(changeset) | ||
|
||
logger.info("Finished migrating environments to v2 for project %d", project_id) | ||
|
||
|
||
def _iter_paginated_overrides( | ||
*, | ||
identity_wrapper: DynamoIdentityWrapper, | ||
environments: Iterable[Environment], | ||
) -> Generator[IdentityOverrideV2, None, None]: | ||
for environment in environments: | ||
environment_api_key = environment.api_key | ||
for identity in identity_wrapper.iter_all_items_paginated( | ||
environment_api_key=environment_api_key, | ||
): | ||
for feature_state in identity.identity_features: | ||
yield map_engine_feature_state_to_identity_override( | ||
feature_state=feature_state, | ||
identity_uuid=str(identity.identity_uuid), | ||
identifier=identity.identifier, | ||
environment_api_key=environment_api_key, | ||
environment_id=str(environment.id), | ||
) |
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
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
Oops, something went wrong.
574a08e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docs – ./docs
docs.flagsmith.com
docs-git-main-flagsmith.vercel.app
docs-flagsmith.vercel.app
docs.bullet-train.io
574a08e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
flagsmith-frontend-preview – ./frontend
flagsmith-frontend-preview-flagsmith.vercel.app
flagsmith-frontend-production-native.vercel.app
flagsmith-frontend-preview-git-main-flagsmith.vercel.app
574a08e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
flagsmith-frontend-staging – ./frontend
flagsmith-staging-frontend.vercel.app
flagsmith-frontend-staging-flagsmith.vercel.app
flagsmith-frontend-staging-git-main-flagsmith.vercel.app
staging.flagsmith.com