dsw-database 4.17.0__tar.gz → 4.18.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dsw_database-4.17.0/dsw_database.egg-info → dsw_database-4.18.1}/PKG-INFO +2 -2
- {dsw_database-4.17.0 → dsw_database-4.18.1}/dsw/database/build_info.py +4 -4
- {dsw_database-4.17.0 → dsw_database-4.18.1}/dsw/database/database.py +90 -8
- {dsw_database-4.17.0 → dsw_database-4.18.1}/dsw/database/model.py +42 -0
- {dsw_database-4.17.0 → dsw_database-4.18.1/dsw_database.egg-info}/PKG-INFO +2 -2
- {dsw_database-4.17.0 → dsw_database-4.18.1}/dsw_database.egg-info/requires.txt +1 -1
- {dsw_database-4.17.0 → dsw_database-4.18.1}/pyproject.toml +2 -2
- {dsw_database-4.17.0 → dsw_database-4.18.1}/LICENSE +0 -0
- {dsw_database-4.17.0 → dsw_database-4.18.1}/README.md +0 -0
- {dsw_database-4.17.0 → dsw_database-4.18.1}/dsw/database/__init__.py +0 -0
- {dsw_database-4.17.0 → dsw_database-4.18.1}/dsw_database.egg-info/SOURCES.txt +0 -0
- {dsw_database-4.17.0 → dsw_database-4.18.1}/dsw_database.egg-info/dependency_links.txt +0 -0
- {dsw_database-4.17.0 → dsw_database-4.18.1}/dsw_database.egg-info/not-zip-safe +0 -0
- {dsw_database-4.17.0 → dsw_database-4.18.1}/dsw_database.egg-info/top_level.txt +0 -0
- {dsw_database-4.17.0 → dsw_database-4.18.1}/setup.cfg +0 -0
- {dsw_database-4.17.0 → dsw_database-4.18.1}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dsw-database
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.18.1
|
|
4
4
|
Summary: Library for managing DSW database
|
|
5
5
|
Author-email: Marek Suchánek <marek.suchanek@ds-wizard.org>
|
|
6
6
|
License: Apache License 2.0
|
|
@@ -20,7 +20,7 @@ Description-Content-Type: text/markdown
|
|
|
20
20
|
License-File: LICENSE
|
|
21
21
|
Requires-Dist: psycopg[binary]
|
|
22
22
|
Requires-Dist: tenacity
|
|
23
|
-
Requires-Dist: dsw-config==4.
|
|
23
|
+
Requires-Dist: dsw-config==4.18.1
|
|
24
24
|
Dynamic: license-file
|
|
25
25
|
|
|
26
26
|
# Data Stewardship Wizard: Database
|
|
@@ -9,9 +9,9 @@ BuildInfo = namedtuple(
|
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
BUILD_INFO = BuildInfo(
|
|
12
|
-
version='v4.
|
|
13
|
-
built_at='2025-
|
|
14
|
-
sha='
|
|
12
|
+
version='v4.18.1~91c8ad3',
|
|
13
|
+
built_at='2025-05-08 06:40:31Z',
|
|
14
|
+
sha='91c8ad3de64417b0caecd45420300dbfe2b2ae08',
|
|
15
15
|
branch='HEAD',
|
|
16
|
-
tag='v4.
|
|
16
|
+
tag='v4.18.1',
|
|
17
17
|
)
|
|
@@ -13,7 +13,8 @@ from dsw.config.model import DatabaseConfig
|
|
|
13
13
|
from .model import DBDocumentTemplate, DBDocumentTemplateFile, \
|
|
14
14
|
DBDocumentTemplateAsset, DBDocument, DBComponent, \
|
|
15
15
|
DocumentState, DBTenantConfig, DBTenantLimits, DBSubmission, \
|
|
16
|
-
DBInstanceConfigMail, DBQuestionnaireSimple
|
|
16
|
+
DBInstanceConfigMail, DBQuestionnaireSimple, \
|
|
17
|
+
DBUserEntity, DBLocale
|
|
17
18
|
|
|
18
19
|
LOG = logging.getLogger(__name__)
|
|
19
20
|
|
|
@@ -59,10 +60,8 @@ class Database:
|
|
|
59
60
|
'WHERE document_template_id = %s AND tenant_uuid = %s;')
|
|
60
61
|
CHECK_TABLE_EXISTS = ('SELECT EXISTS(SELECT * FROM information_schema.tables'
|
|
61
62
|
' WHERE table_name = %(table_name)s)')
|
|
62
|
-
SELECT_MAIL_CONFIG = ('SELECT
|
|
63
|
-
'
|
|
64
|
-
'ON tc.mail_config_uuid = icm.uuid '
|
|
65
|
-
'WHERE tc.uuid = %(tenant_uuid)s;')
|
|
63
|
+
SELECT_MAIL_CONFIG = ('SELECT * FROM instance_config_mail '
|
|
64
|
+
'WHERE uuid = %(mail_config_uuid)s;')
|
|
66
65
|
UPDATE_COMPONENT_INFO = ('INSERT INTO component '
|
|
67
66
|
'(name, version, built_at, created_at, updated_at) '
|
|
68
67
|
'VALUES (%(name)s, %(version)s, %(built_at)s, '
|
|
@@ -78,6 +77,14 @@ class Database:
|
|
|
78
77
|
'+ (SELECT COALESCE(SUM(file_size)::bigint, 0) '
|
|
79
78
|
'FROM questionnaire_file WHERE tenant_uuid = %(tenant_uuid)s) '
|
|
80
79
|
'AS result;')
|
|
80
|
+
SELECT_USER = ('SELECT * FROM user_entity '
|
|
81
|
+
'WHERE uuid = %(user_uuid)s AND tenant_uuid = %(tenant_uuid)s;')
|
|
82
|
+
SELECT_DEFAULT_LOCALE = ('SELECT * FROM locale '
|
|
83
|
+
'WHERE default_locale IS TRUE AND '
|
|
84
|
+
' enabled is TRUE AND '
|
|
85
|
+
' tenant_uuid = %(tenant_uuid)s;')
|
|
86
|
+
SELECT_LOCALE = ('SELECT * FROM locale '
|
|
87
|
+
'WHERE id = %(locale_id)s AND tenant_uuid = %(tenant_uuid)s;')
|
|
81
88
|
|
|
82
89
|
def __init__(self, cfg: DatabaseConfig, connect: bool = True,
|
|
83
90
|
with_queue: bool = True):
|
|
@@ -397,24 +404,99 @@ class Database:
|
|
|
397
404
|
before=tenacity.before_log(LOG, logging.DEBUG),
|
|
398
405
|
after=tenacity.after_log(LOG, logging.DEBUG),
|
|
399
406
|
)
|
|
400
|
-
def get_mail_config(self,
|
|
407
|
+
def get_mail_config(self, mail_config_uuid: str) -> DBInstanceConfigMail | None:
|
|
401
408
|
with self.conn_query.new_cursor(use_dict=True) as cursor:
|
|
402
409
|
if not self._check_table_exists(table_name='instance_config_mail'):
|
|
403
410
|
return None
|
|
404
411
|
try:
|
|
405
412
|
cursor.execute(
|
|
406
413
|
query=self.SELECT_MAIL_CONFIG,
|
|
407
|
-
params={'
|
|
414
|
+
params={'mail_config_uuid': mail_config_uuid},
|
|
408
415
|
)
|
|
409
416
|
result = cursor.fetchone()
|
|
410
417
|
if result is None:
|
|
411
418
|
return None
|
|
412
419
|
return DBInstanceConfigMail.from_dict_row(data=result)
|
|
413
420
|
except Exception as e:
|
|
414
|
-
LOG.warning('Could not retrieve instance_config_mail
|
|
421
|
+
LOG.warning('Could not retrieve instance_config_mail "%s": %s',
|
|
422
|
+
mail_config_uuid, str(e))
|
|
423
|
+
return None
|
|
424
|
+
|
|
425
|
+
@tenacity.retry(
|
|
426
|
+
reraise=True,
|
|
427
|
+
wait=tenacity.wait_exponential(multiplier=RETRY_QUERY_MULTIPLIER),
|
|
428
|
+
stop=tenacity.stop_after_attempt(RETRY_QUERY_TRIES),
|
|
429
|
+
before=tenacity.before_log(LOG, logging.DEBUG),
|
|
430
|
+
after=tenacity.after_log(LOG, logging.DEBUG),
|
|
431
|
+
)
|
|
432
|
+
def get_user(self, user_uuid: str, tenant_uuid: str) -> DBUserEntity | None:
|
|
433
|
+
if not self._check_table_exists(table_name='user_entity'):
|
|
434
|
+
return None
|
|
435
|
+
with self.conn_query.new_cursor(use_dict=True) as cursor:
|
|
436
|
+
try:
|
|
437
|
+
cursor.execute(
|
|
438
|
+
query=self.SELECT_USER,
|
|
439
|
+
params={'user_uuid': user_uuid, 'tenant_uuid': tenant_uuid},
|
|
440
|
+
)
|
|
441
|
+
result = cursor.fetchone()
|
|
442
|
+
if result is None:
|
|
443
|
+
return None
|
|
444
|
+
return DBUserEntity.from_dict_row(data=result)
|
|
445
|
+
except Exception as e:
|
|
446
|
+
LOG.warning('Could not retrieve user "%s" for tenant "%s": %s',
|
|
447
|
+
user_uuid, tenant_uuid, str(e))
|
|
448
|
+
return None
|
|
449
|
+
|
|
450
|
+
@tenacity.retry(
|
|
451
|
+
reraise=True,
|
|
452
|
+
wait=tenacity.wait_exponential(multiplier=RETRY_QUERY_MULTIPLIER),
|
|
453
|
+
stop=tenacity.stop_after_attempt(RETRY_QUERY_TRIES),
|
|
454
|
+
before=tenacity.before_log(LOG, logging.DEBUG),
|
|
455
|
+
after=tenacity.after_log(LOG, logging.DEBUG),
|
|
456
|
+
)
|
|
457
|
+
def get_default_locale(self, tenant_uuid: str) -> DBLocale | None:
|
|
458
|
+
if not self._check_table_exists(table_name='locale'):
|
|
459
|
+
return None
|
|
460
|
+
with self.conn_query.new_cursor(use_dict=True) as cursor:
|
|
461
|
+
try:
|
|
462
|
+
cursor.execute(
|
|
463
|
+
query=self.SELECT_DEFAULT_LOCALE,
|
|
464
|
+
params={'tenant_uuid': tenant_uuid},
|
|
465
|
+
)
|
|
466
|
+
result = cursor.fetchone()
|
|
467
|
+
if result is None:
|
|
468
|
+
return None
|
|
469
|
+
return DBLocale.from_dict_row(data=result)
|
|
470
|
+
except Exception as e:
|
|
471
|
+
LOG.warning('Could not retrieve default locale for tenant "%s": %s',
|
|
415
472
|
tenant_uuid, str(e))
|
|
416
473
|
return None
|
|
417
474
|
|
|
475
|
+
@tenacity.retry(
|
|
476
|
+
reraise=True,
|
|
477
|
+
wait=tenacity.wait_exponential(multiplier=RETRY_QUERY_MULTIPLIER),
|
|
478
|
+
stop=tenacity.stop_after_attempt(RETRY_QUERY_TRIES),
|
|
479
|
+
before=tenacity.before_log(LOG, logging.DEBUG),
|
|
480
|
+
after=tenacity.after_log(LOG, logging.DEBUG),
|
|
481
|
+
)
|
|
482
|
+
def get_locale(self, locale_id: str, tenant_uuid: str) -> DBLocale | None:
|
|
483
|
+
if not self._check_table_exists(table_name='locale'):
|
|
484
|
+
return None
|
|
485
|
+
with self.conn_query.new_cursor(use_dict=True) as cursor:
|
|
486
|
+
try:
|
|
487
|
+
cursor.execute(
|
|
488
|
+
query=self.SELECT_LOCALE,
|
|
489
|
+
params={'locale_id': locale_id, 'tenant_uuid': tenant_uuid},
|
|
490
|
+
)
|
|
491
|
+
result = cursor.fetchone()
|
|
492
|
+
if result is None:
|
|
493
|
+
return None
|
|
494
|
+
return DBLocale.from_dict_row(data=result)
|
|
495
|
+
except Exception as e:
|
|
496
|
+
LOG.warning('Could not retrieve locale "%s" for tenant "%s": %s',
|
|
497
|
+
locale_id, tenant_uuid, str(e))
|
|
498
|
+
return None
|
|
499
|
+
|
|
418
500
|
@tenacity.retry(
|
|
419
501
|
reraise=True,
|
|
420
502
|
wait=tenacity.wait_exponential(multiplier=RETRY_QUERY_MULTIPLIER),
|
|
@@ -382,6 +382,48 @@ class DBQuestionnaireSimple:
|
|
|
382
382
|
}
|
|
383
383
|
|
|
384
384
|
|
|
385
|
+
@dataclasses.dataclass
|
|
386
|
+
class DBUserEntity:
|
|
387
|
+
TABLE_NAME = 'user_entity'
|
|
388
|
+
|
|
389
|
+
uuid: str
|
|
390
|
+
first_name: str
|
|
391
|
+
last_name: str
|
|
392
|
+
email: str
|
|
393
|
+
locale: str | None
|
|
394
|
+
|
|
395
|
+
@staticmethod
|
|
396
|
+
def from_dict_row(data: dict):
|
|
397
|
+
return DBUserEntity(
|
|
398
|
+
uuid=str(data['uuid']),
|
|
399
|
+
first_name=data['first_name'],
|
|
400
|
+
last_name=data['last_name'],
|
|
401
|
+
email=data['email'],
|
|
402
|
+
locale=data['locale'],
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
@dataclasses.dataclass
|
|
407
|
+
class DBLocale:
|
|
408
|
+
TABLE_NAME = 'locale'
|
|
409
|
+
|
|
410
|
+
id: str
|
|
411
|
+
name: str
|
|
412
|
+
code: str
|
|
413
|
+
default_locale: bool
|
|
414
|
+
enabled: bool
|
|
415
|
+
|
|
416
|
+
@staticmethod
|
|
417
|
+
def from_dict_row(data: dict):
|
|
418
|
+
return DBLocale(
|
|
419
|
+
id=str(data['id']),
|
|
420
|
+
name=data['name'],
|
|
421
|
+
code=data['code'],
|
|
422
|
+
default_locale=data['default_locale'],
|
|
423
|
+
enabled=data['enabled'],
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
|
|
385
427
|
@dataclasses.dataclass
|
|
386
428
|
class DBInstanceConfigMail:
|
|
387
429
|
TABLE_NAME = 'instance_config_mail'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dsw-database
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.18.1
|
|
4
4
|
Summary: Library for managing DSW database
|
|
5
5
|
Author-email: Marek Suchánek <marek.suchanek@ds-wizard.org>
|
|
6
6
|
License: Apache License 2.0
|
|
@@ -20,7 +20,7 @@ Description-Content-Type: text/markdown
|
|
|
20
20
|
License-File: LICENSE
|
|
21
21
|
Requires-Dist: psycopg[binary]
|
|
22
22
|
Requires-Dist: tenacity
|
|
23
|
-
Requires-Dist: dsw-config==4.
|
|
23
|
+
Requires-Dist: dsw-config==4.18.1
|
|
24
24
|
Dynamic: license-file
|
|
25
25
|
|
|
26
26
|
# Data Stewardship Wizard: Database
|
|
@@ -4,7 +4,7 @@ build-backend = 'setuptools.build_meta'
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = 'dsw-database'
|
|
7
|
-
version = "4.
|
|
7
|
+
version = "4.18.1"
|
|
8
8
|
description = 'Library for managing DSW database'
|
|
9
9
|
readme = 'README.md'
|
|
10
10
|
keywords = ['dsw', 'database']
|
|
@@ -26,7 +26,7 @@ dependencies = [
|
|
|
26
26
|
'psycopg[binary]',
|
|
27
27
|
'tenacity',
|
|
28
28
|
# DSW
|
|
29
|
-
"dsw-config==4.
|
|
29
|
+
"dsw-config==4.18.1",
|
|
30
30
|
]
|
|
31
31
|
|
|
32
32
|
[project.urls]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|