remove prefix for partition key

This commit is contained in:
2025-03-26 15:27:26 -03:00
parent 3564119581
commit 3d6801df70
7 changed files with 68 additions and 16 deletions

View File

@@ -17,6 +17,7 @@ from layercake.dynamodb import (
KeyPair,
MissingError,
PartitionKey,
PrefixKey,
)
from pydantic import UUID4, BaseModel, StringConstraints
@@ -89,7 +90,7 @@ def get_emails(id: str):
start_key = router.current_event.get_query_string_value('start_key', None)
return collect.get_items(
key=KeyPair(id, 'emails'),
KeyPair(id, PrefixKey('emails#')),
start_key=start_key,
)
@@ -104,7 +105,9 @@ def get_logs(id: str):
start_key = router.current_event.get_query_string_value('start_key', None)
return collect.get_items(
key=PartitionKey(ComposeKey(id, prefix='log', delimiter=':')),
# Post-migration: uncomment to enable PartitionKey with a composite key (id with `logs` prefix).
# PartitionKey(ComposeKey(id, prefix='logs')),
PartitionKey(ComposeKey(id, prefix='log', delimiter=':')),
start_key=start_key,
)
@@ -119,6 +122,6 @@ def get_orgs(id: str):
start_key = router.current_event.get_query_string_value('start_key', None)
return collect.get_items(
key=KeyPair(id, 'orgs'),
KeyPair(id, PrefixKey('orgs#')),
start_key=start_key,
)

View File

@@ -29,7 +29,7 @@ def test_get_emails(
{
'email_verified': True,
'mx_record_exists': True,
'sk': 'emails#sergio@somosbeta.com.br',
'sk': 'sergio@somosbeta.com.br',
'email_primary': True,
'id': '5OxmMjL-ujoR5IMGegQz',
'create_date': '2019-03-25T00:00:00-03:00',
@@ -40,6 +40,28 @@ def test_get_emails(
}
def test_get_logs(
mock_app,
dynamodb_seeds,
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
http_api_proxy: HttpApiProxy,
lambda_context: LambdaContext,
):
mock_app.users.collect = DynamoDBCollection(dynamodb_persistence_layer)
r = mock_app.lambda_handler(
http_api_proxy(
raw_path='/users/5OxmMjL-ujoR5IMGegQz/logs',
method=HTTPMethod.GET,
),
lambda_context,
)
assert r['statusCode'] == HTTPStatus.OK
print(r['body'])
def test_post_user(
mock_app,
http_api_proxy: HttpApiProxy,

View File

@@ -4,5 +4,5 @@
{"id": {"S": "5OxmMjL-ujoR5IMGegQz"}, "sk": {"S": "acls#*"}, "create_date": {"S": "2022-06-13T15:00:24.309410-03:00"}, "roles": {"L": [{"S": "ADMIN"}]}}
{"id": {"S": "5OxmMjL-ujoR5IMGegQz"}, "sk": {"S": "acls#cJtK9SsnJhKPyxESe7g3DG"}, "create_date": {"S": "2025-03-14T10:06:34.628078-03:00"}, "roles": {"L": [{"S": "ADMIN"}]}}
{"id": {"S": "5OxmMjL-ujoR5IMGegQz"}, "sk": {"S": "orgs#cJtK9SsnJhKPyxESe7g3DG"}, "cnpj": {"S": "15608435000190"}, "create_date": {"S": "2025-03-13T16:36:50.073156-03:00"}, "name": {"S": "Beta Educação"}}
{"id": {"S": "logs#5OxmMjL-ujoR5IMGegQz"}, "sk": {"S": "2024-02-08T16:42:33.776409-03:00"}, "action": {"S": "OPEN_EMAIL"}}
{"id": {"S": "logs#5OxmMjL-ujoR5IMGegQz"}, "sk": {"S": "2019-03-25T00:00:00-03:00"}, "action": {"S": "CLICK_EMAIL"}}
{"id": {"S": "log:5OxmMjL-ujoR5IMGegQz"}, "sk": {"S": "2024-02-08T16:42:33.776409-03:00"}, "action": {"S": "OPEN_EMAIL"}}
{"id": {"S": "log:5OxmMjL-ujoR5IMGegQz"}, "sk": {"S": "2019-03-25T00:00:00-03:00"}, "action": {"S": "CLICK_EMAIL"}}