From 564c4e4a972a99eda0b6b5ab38a35abde03c33ad Mon Sep 17 00:00:00 2001 From: Kristoffer Andersson Date: Mon, 28 Mar 2022 11:06:28 +0200 Subject: [PATCH] fix: shorten the table name --- karp/lex_infrastructure/repositories/sql_entries.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/karp/lex_infrastructure/repositories/sql_entries.py b/karp/lex_infrastructure/repositories/sql_entries.py index 2f575d29..0a46376b 100644 --- a/karp/lex_infrastructure/repositories/sql_entries.py +++ b/karp/lex_infrastructure/repositories/sql_entries.py @@ -1,16 +1,14 @@ """SQL repositories for entries.""" -import inspect import logging import typing -from typing import Dict, List, Optional, Tuple, Generic, TypeVar -from uuid import UUID +from typing import Dict, List, Optional, Generic, TypeVar import injector import regex import sqlalchemy as sa from sqlalchemy import sql from sqlalchemy.orm import sessionmaker -import logging +import ulid from karp.foundation.value_objects import UniqueId from karp.foundation.events import EventBus @@ -190,7 +188,7 @@ def _save(self, entry: Entry): { 'entry_by_entry_id': entry_by_entry_id, 'entry_by_entity_id': entry_by_entity_id, - 'entry': entry.dict(), + 'entry': entry.dict(), } ) raise RuntimeError(f'entry = {entry.dict()}') @@ -619,7 +617,9 @@ class SqlEntryUnitOfWorkV2(SqlEntryUnitOfWork): repository_type: str = 'sql_entries_v2' def table_name(self) -> str: - return f"{self.name}_{self.entity_id.hex}" + u = ulid.from_uuid(self.entity_id) + random_part = u.randomness().str + return f"{self.name}_{random_part}" # ===== Value objects ===== # class SqlEntryRepositorySettings(EntryRepositorySettings):