Skip to content

Commit fe067e6

Browse files
committed
refactor: Refactor KM/DT ID to UUID
1 parent 320f809 commit fe067e6

32 files changed

+6104
-7027
lines changed

.cspell/dictionary.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,21 @@ Marek
102102
Suchánek
103103
Kazuki
104104
Yamamoto
105+
106+
# Things appearing in VCR cassettes
107+
stylesheet
108+
flexbox
109+
Vtnp
110+
Hgotu
111+
komanec
112+
krystof
113+
krystofkomanec
114+
DNkov
115+
martinkova
116+
jmartinkova
117+
odend
118+
heighta
119+
xurl
120+
nosniff
121+
122+

packages/dsw-database/dsw/database/database.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ class Database:
4949
'file_name = %s, content_type = %s, worker_log = %s, '
5050
'file_size = %s WHERE uuid = %s;')
5151
SELECT_TEMPLATE = ('SELECT * FROM document_template '
52-
'WHERE id = %s AND tenant_uuid = %s LIMIT 1;')
52+
'WHERE uuid = %s AND tenant_uuid = %s LIMIT 1;')
5353
SELECT_TEMPLATE_FORMATS = ('SELECT * FROM document_template_format '
54-
'WHERE document_template_id = %s AND tenant_uuid = %s;')
54+
'WHERE document_template_uuid = %s AND tenant_uuid = %s;')
5555
SELECT_TEMPLATE_STEPS = ('SELECT * FROM document_template_format_step '
56-
'WHERE document_template_id = %s AND tenant_uuid = %s;')
56+
'WHERE document_template_uuid = %s AND tenant_uuid = %s;')
5757
SELECT_TEMPLATE_FILES = ('SELECT * FROM document_template_file '
58-
'WHERE document_template_id = %s AND tenant_uuid = %s;')
58+
'WHERE document_template_uuid = %s AND tenant_uuid = %s;')
5959
SELECT_TEMPLATE_ASSETS = ('SELECT * FROM document_template_asset '
60-
'WHERE document_template_id = %s AND tenant_uuid = %s;')
60+
'WHERE document_template_uuid = %s AND tenant_uuid = %s;')
6161
CHECK_TABLE_EXISTS = ('SELECT EXISTS(SELECT * FROM information_schema.tables'
6262
' WHERE table_name = %(table_name)s)')
6363
SELECT_MAIL_CONFIG = ('SELECT * FROM instance_config_mail '
@@ -177,12 +177,12 @@ def fetch_tenant_limits(self, tenant_uuid: str) -> model.DBTenantLimits | None:
177177
after=tenacity.after_log(LOG, logging.DEBUG),
178178
)
179179
def fetch_template(
180-
self, template_id: str, tenant_uuid: str,
180+
self, template_uuid: str, tenant_uuid: str,
181181
) -> model.DBDocumentTemplate | None:
182182
with self.conn_query.new_cursor(use_dict=True) as cursor:
183183
cursor.execute(
184184
query=self.SELECT_TEMPLATE,
185-
params=(template_id, tenant_uuid),
185+
params=(template_uuid, tenant_uuid),
186186
)
187187
dt_result = cursor.fetchall()
188188
if len(dt_result) != 1:
@@ -191,15 +191,15 @@ def fetch_template(
191191

192192
cursor.execute(
193193
query=self.SELECT_TEMPLATE_FORMATS,
194-
params=(template_id, tenant_uuid),
194+
params=(template_uuid, tenant_uuid),
195195
)
196196
formats_result = cursor.fetchall()
197197
formats = sorted([
198198
model.DBDocumentTemplateFormat.from_dict_row(x) for x in formats_result
199199
], key=lambda x: x.name)
200200
cursor.execute(
201201
query=self.SELECT_TEMPLATE_STEPS,
202-
params=(template_id, tenant_uuid),
202+
params=(template_uuid, tenant_uuid),
203203
)
204204
steps_result = cursor.fetchall()
205205
steps = sorted([
@@ -229,12 +229,12 @@ def fetch_template(
229229
after=tenacity.after_log(LOG, logging.DEBUG),
230230
)
231231
def fetch_template_files(
232-
self, template_id: str, tenant_uuid: str,
232+
self, template_uuid: str, tenant_uuid: str,
233233
) -> list[model.DBDocumentTemplateFile]:
234234
with self.conn_query.new_cursor(use_dict=True) as cursor:
235235
cursor.execute(
236236
query=self.SELECT_TEMPLATE_FILES,
237-
params=(template_id, tenant_uuid),
237+
params=(template_uuid, tenant_uuid),
238238
)
239239
return [model.DBDocumentTemplateFile.from_dict_row(x) for x in cursor.fetchall()]
240240

@@ -246,12 +246,12 @@ def fetch_template_files(
246246
after=tenacity.after_log(LOG, logging.DEBUG),
247247
)
248248
def fetch_template_assets(
249-
self, template_id: str, tenant_uuid: str,
249+
self, template_uuid: str, tenant_uuid: str,
250250
) -> list[model.DBDocumentTemplateAsset]:
251251
with self.conn_query.new_cursor(use_dict=True) as cursor:
252252
cursor.execute(
253253
query=self.SELECT_TEMPLATE_ASSETS,
254-
params=(template_id, tenant_uuid),
254+
params=(template_uuid, tenant_uuid),
255255
)
256256
return [model.DBDocumentTemplateAsset.from_dict_row(x) for x in cursor.fetchall()]
257257

packages/dsw-database/dsw/database/model.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class DBDocument:
4848
project_uuid: str | None
4949
project_event_uuid: str | None
5050
project_replies_hash: str
51-
document_template_id: str
51+
document_template_uuid: str
5252
format_uuid: str
5353
file_name: str
5454
content_type: str
@@ -72,7 +72,7 @@ def from_dict_row(data: dict):
7272
project_uuid=str(project_uuid) if project_uuid else None,
7373
project_event_uuid=str(event_uuid) if event_uuid else None,
7474
project_replies_hash=data['project_replies_hash'],
75-
document_template_id=data['document_template_id'],
75+
document_template_uuid=data['document_template_uuid'],
7676
format_uuid=str(data['format_uuid']),
7777
created_by=str(data['created_by']),
7878
retrieved_at=data['retrieved_at'],
@@ -88,7 +88,7 @@ def from_dict_row(data: dict):
8888

8989
@dataclasses.dataclass
9090
class DBDocumentTemplate:
91-
id: str
91+
uuid: str
9292
name: str
9393
organization_id: str
9494
template_id: str
@@ -116,10 +116,14 @@ def is_released(self):
116116
def is_deprecated(self):
117117
return self.phase == DocumentTemplatePhase.DEPRECATED
118118

119+
@property
120+
def coordinates(self) -> str:
121+
return f'{self.organization_id}:{self.template_id}:{self.version}'
122+
119123
@staticmethod
120124
def from_dict_row(data: dict) -> 'DBDocumentTemplate':
121125
return DBDocumentTemplate(
122-
id=data['id'],
126+
uuid=data['uuid'],
123127
name=data['name'],
124128
organization_id=data['organization_id'],
125129
template_id=data['template_id'],
@@ -139,7 +143,7 @@ def from_dict_row(data: dict) -> 'DBDocumentTemplate':
139143

140144
@dataclasses.dataclass
141145
class DBDocumentTemplateFormat:
142-
document_template_id: str
146+
document_template_uuid: str
143147
uuid: str
144148
name: str
145149
icon: str
@@ -150,7 +154,7 @@ class DBDocumentTemplateFormat:
150154
@staticmethod
151155
def from_dict_row(data: dict) -> 'DBDocumentTemplateFormat':
152156
return DBDocumentTemplateFormat(
153-
document_template_id=data['document_template_id'],
157+
document_template_uuid=data['document_template_uuid'],
154158
uuid=str(data['uuid']),
155159
name=data['name'],
156160
icon=data['icon'],
@@ -162,7 +166,7 @@ def from_dict_row(data: dict) -> 'DBDocumentTemplateFormat':
162166

163167
@dataclasses.dataclass
164168
class DBDocumentTemplateStep:
165-
document_template_id: str
169+
document_template_uuid: str
166170
format_uuid: str
167171
position: int
168172
name: str
@@ -174,7 +178,7 @@ class DBDocumentTemplateStep:
174178
@staticmethod
175179
def from_dict_row(data: dict) -> 'DBDocumentTemplateStep':
176180
return DBDocumentTemplateStep(
177-
document_template_id=data['document_template_id'],
181+
document_template_uuid=data['document_template_uuid'],
178182
format_uuid=str(data['format_uuid']),
179183
position=data['position'],
180184
name=data['name'],
@@ -187,7 +191,7 @@ def from_dict_row(data: dict) -> 'DBDocumentTemplateStep':
187191

188192
@dataclasses.dataclass
189193
class DBDocumentTemplateFile:
190-
document_template_id: str
194+
document_template_uuid: str
191195
uuid: str
192196
file_name: str
193197
content: str
@@ -198,7 +202,7 @@ class DBDocumentTemplateFile:
198202
@staticmethod
199203
def from_dict_row(data: dict) -> 'DBDocumentTemplateFile':
200204
return DBDocumentTemplateFile(
201-
document_template_id=data['document_template_id'],
205+
document_template_uuid=data['document_template_uuid'],
202206
uuid=str(data['uuid']),
203207
file_name=data['file_name'],
204208
content=data['content'],
@@ -210,7 +214,7 @@ def from_dict_row(data: dict) -> 'DBDocumentTemplateFile':
210214

211215
@dataclasses.dataclass
212216
class DBDocumentTemplateAsset:
213-
document_template_id: str
217+
document_template_uuid: str
214218
uuid: str
215219
file_name: str
216220
content_type: str
@@ -222,7 +226,7 @@ class DBDocumentTemplateAsset:
222226
@staticmethod
223227
def from_dict_row(data: dict) -> 'DBDocumentTemplateAsset':
224228
return DBDocumentTemplateAsset(
225-
document_template_id=data['document_template_id'],
229+
document_template_uuid=data['document_template_uuid'],
226230
uuid=str(data['uuid']),
227231
file_name=data['file_name'],
228232
content_type=data['content_type'],
@@ -334,8 +338,8 @@ class DBProjectSimple:
334338
name: str
335339
visibility: str
336340
sharing: str
337-
package_id: str
338-
document_template_id: str
341+
knowledge_package_uuid: str
342+
document_template_uuid: str
339343
format_uuid: str
340344
created_by: str
341345
created_at: datetime.datetime
@@ -352,8 +356,8 @@ def from_dict_row(data: dict):
352356
name=data['name'],
353357
visibility=data['visibility'],
354358
sharing=data['sharing'],
355-
package_id=data['package_id'],
356-
document_template_id=data['document_template_id'],
359+
knowledge_package_uuid=data['knowledge_package_uuid'],
360+
document_template_uuid=data['document_template_uuid'],
357361
format_uuid=str(data['format_uuid']),
358362
created_by=str(data['created_by']),
359363
created_at=data['created_at'],
@@ -370,8 +374,8 @@ def to_dict(self) -> dict:
370374
'name': self.name,
371375
'visibility': self.visibility,
372376
'sharing': self.sharing,
373-
'package_id': self.package_id,
374-
'document_template_id': self.document_template_id,
377+
'knowledge_package_uuid': self.knowledge_package_uuid,
378+
'document_template_uuid': self.document_template_uuid,
375379
'format_uuid': self.format_uuid,
376380
'created_by': self.created_by,
377381
'created_at': self.created_at.isoformat(timespec='milliseconds'),

packages/dsw-document-worker/dsw/document_worker/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ def load(data: dict):
212212
class TemplatesConfig:
213213
templates: list[TemplateConfig]
214214

215-
def get_config(self, template_id: str) -> TemplateConfig | None:
215+
def get_config(self, template_coordinates: str) -> TemplateConfig | None:
216216
for template in self.templates:
217-
if any(template_id.startswith(prefix) for prefix in template.ids):
217+
if any(template_coordinates.startswith(prefix) for prefix in template.ids):
218218
return template
219219
return None
220220

packages/dsw-document-worker/dsw/document_worker/model/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,7 @@ def __init__(self, *, uuid: str, name: str, document_template_id: str, format_uu
18271827
created_by: User | None, created_at: datetime.datetime):
18281828
self.uuid = uuid
18291829
self.name = name
1830-
self.document_template_id = document_template_id
1830+
self.document_template_uuid = document_template_id
18311831
self.format_uuid = format_uuid
18321832
self.created_by = created_by
18331833
self.created_at = created_at

packages/dsw-document-worker/dsw/document_worker/templates/steps/template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def _add_j2_enhancements(self):
135135
self.j2_env.filters.update(filters)
136136
self.j2_env.tests.update(tests)
137137
template_cfg = Context.get().app.cfg.templates.get_config(
138-
self.template.template_id,
138+
self.template.coordinates,
139139
)
140140
self.j2_env.globals.update({'rdflib': rdflib, 'json': json})
141141
if template_cfg is not None:

0 commit comments

Comments
 (0)