add scope to id

This commit is contained in:
2025-10-24 20:05:56 -03:00
parent c68aa98fc9
commit c4509f5072
18 changed files with 173 additions and 58 deletions

View File

@@ -7,6 +7,7 @@ from typing import Generator
import jsonlines
from aws_lambda_powertools.shared.json_encoder import Encoder
from layercake.dynamodb import deserialize
from layercake.strutils import md5_hash
from tqdm import tqdm
@@ -42,7 +43,12 @@ if __name__ == '__main__':
with sqlite3.connect('mydatabase.db') as conn:
cursor = conn.cursor()
cursor.execute(
'CREATE TABLE IF NOT EXISTS %s (pk TEXT, sk TEXT, json JSON)'
"""
CREATE TABLE IF NOT EXISTS %s (
_id TEXT PRIMARY KEY,
json JSON NOT NULL
)
"""
% table_name
)
@@ -50,12 +56,19 @@ if __name__ == '__main__':
readlines(input_dirpath),
desc=f'⏳ Inserting into table {table_name}',
):
_id = md5_hash(
str(
{
'id': record['id'],
'sk': record['sk'],
}
)
)
cursor.execute(
'INSERT INTO %s (pk, sk, json) VALUES (:pk, :sk, :json)'
% table_name,
'INSERT INTO %s (_id, json) VALUES (:_id, :json)' % table_name,
{
'pk': record['id'],
'sk': record['sk'],
'_id': _id,
'json': record,
},
)

View File

@@ -14,6 +14,7 @@ dev = [
"pycouchdb>=1.16.0",
"pytest>=8.3.4",
"pytest-cov>=6.0.0",
"python-slugify>=8.0.4",
"ruff>=0.9.1",
"sqlite-utils>=3.38",
"tqdm>=4.67.1",

23
http-api/uv.lock generated
View File

@@ -435,6 +435,7 @@ dev = [
{ name = "pycouchdb" },
{ name = "pytest" },
{ name = "pytest-cov" },
{ name = "python-slugify" },
{ name = "ruff" },
{ name = "sqlite-utils" },
{ name = "tqdm" },
@@ -451,6 +452,7 @@ dev = [
{ name = "pycouchdb", specifier = ">=1.16.0" },
{ name = "pytest", specifier = ">=8.3.4" },
{ name = "pytest-cov", specifier = ">=6.0.0" },
{ name = "python-slugify", specifier = ">=8.0.4" },
{ name = "ruff", specifier = ">=0.9.1" },
{ name = "sqlite-utils", specifier = ">=3.38" },
{ name = "tqdm", specifier = ">=4.67.1" },
@@ -937,6 +939,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/45/58/38b5afbc1a800eeea951b9285d3912613f2603bdf897a4ab0f4bd7f405fc/python_multipart-0.0.20-py3-none-any.whl", hash = "sha256:8a62d3a8335e06589fe01f2a3e178cdcc632f3fbe0d492ad9ee0ec35aab1f104", size = 24546, upload-time = "2024-12-16T19:45:44.423Z" },
]
[[package]]
name = "python-slugify"
version = "8.0.4"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "text-unidecode" },
]
sdist = { url = "https://files.pythonhosted.org/packages/87/c7/5e1547c44e31da50a460df93af11a535ace568ef89d7a811069ead340c4a/python-slugify-8.0.4.tar.gz", hash = "sha256:59202371d1d05b54a9e7720c5e038f928f45daaffe41dd10822f3907b937c856", size = 10921, upload-time = "2024-02-08T18:32:45.488Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/a4/62/02da182e544a51a5c3ccf4b03ab79df279f9c60c5e82d5e8bec7ca26ac11/python_slugify-8.0.4-py2.py3-none-any.whl", hash = "sha256:276540b79961052b66b7d116620b36518847f52d5fd9e3a70164fc8c50faa6b8", size = 10051, upload-time = "2024-02-08T18:32:43.911Z" },
]
[[package]]
name = "pytz"
version = "2025.2"
@@ -1059,6 +1073,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/40/44/4a5f08c96eb108af5cb50b41f76142f0afa346dfa99d5296fe7202a11854/tabulate-0.9.0-py3-none-any.whl", hash = "sha256:024ca478df22e9340661486f85298cff5f6dcdba14f3813e8830015b9ed1948f", size = 35252, upload-time = "2022-10-06T17:21:44.262Z" },
]
[[package]]
name = "text-unidecode"
version = "1.3"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/ab/e2/e9a00f0ccb71718418230718b3d900e71a5d16e701a3dae079a21e9cd8f8/text-unidecode-1.3.tar.gz", hash = "sha256:bad6603bb14d279193107714b288be206cac565dfa49aa5b105294dd5c4aab93", size = 76885, upload-time = "2019-08-30T21:36:45.405Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/a6/a5/c0b6468d3824fe3fde30dbb5e1f687b291608f9473681bbf7dabbf5a87d7/text_unidecode-1.3-py2.py3-none-any.whl", hash = "sha256:1311f10e8b895935241623731c2ba64f4c455287888b18189350b67134a822e8", size = 78154, upload-time = "2019-08-30T21:37:03.543Z" },
]
[[package]]
name = "tqdm"
version = "4.67.1"