ecodev-core 0.0.51__py3-none-any.whl → 0.0.53__py3-none-any.whl
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.
Potentially problematic release.
This version of ecodev-core might be problematic. Click here for more details.
- ecodev_core/__init__.py +6 -3
- ecodev_core/db_upsertion.py +32 -6
- ecodev_core/settings.py +0 -5
- {ecodev_core-0.0.51.dist-info → ecodev_core-0.0.53.dist-info}/METADATA +1 -1
- {ecodev_core-0.0.51.dist-info → ecodev_core-0.0.53.dist-info}/RECORD +7 -7
- {ecodev_core-0.0.51.dist-info → ecodev_core-0.0.53.dist-info}/LICENSE.md +0 -0
- {ecodev_core-0.0.51.dist-info → ecodev_core-0.0.53.dist-info}/WHEEL +0 -0
ecodev_core/__init__.py
CHANGED
|
@@ -40,14 +40,15 @@ from ecodev_core.db_insertion import get_raw_df
|
|
|
40
40
|
from ecodev_core.db_retrieval import count_rows
|
|
41
41
|
from ecodev_core.db_retrieval import get_rows
|
|
42
42
|
from ecodev_core.db_retrieval import ServerSideField
|
|
43
|
+
from ecodev_core.db_upsertion import add_missing_enum_values
|
|
43
44
|
from ecodev_core.db_upsertion import field
|
|
45
|
+
from ecodev_core.db_upsertion import filter_to_sfield_dict
|
|
46
|
+
from ecodev_core.db_upsertion import get_sfield_columns
|
|
44
47
|
from ecodev_core.db_upsertion import sfield
|
|
45
48
|
from ecodev_core.db_upsertion import upsert_data
|
|
46
49
|
from ecodev_core.db_upsertion import upsert_deletor
|
|
47
50
|
from ecodev_core.db_upsertion import upsert_df_data
|
|
48
51
|
from ecodev_core.db_upsertion import upsert_selector
|
|
49
|
-
from ecodev_core.db_upsertion import get_sfield_columns
|
|
50
|
-
from ecodev_core.db_upsertion import filter_to_sfield_dict
|
|
51
52
|
from ecodev_core.deployment import Deployment
|
|
52
53
|
from ecodev_core.email_sender import send_email
|
|
53
54
|
from ecodev_core.enum_utils import enum_converter
|
|
@@ -85,6 +86,7 @@ from ecodev_core.safe_utils import safe_clt
|
|
|
85
86
|
from ecodev_core.safe_utils import SafeTestCase
|
|
86
87
|
from ecodev_core.safe_utils import SimpleReturn
|
|
87
88
|
from ecodev_core.safe_utils import stringify
|
|
89
|
+
from ecodev_core.settings import SETTINGS
|
|
88
90
|
from ecodev_core.settings import Settings
|
|
89
91
|
from ecodev_core.version import db_to_value
|
|
90
92
|
from ecodev_core.version import get_row_versions
|
|
@@ -105,4 +107,5 @@ __all__ = [
|
|
|
105
107
|
'datify', 'safe_drop_columns', 'get_value', 'is_null', 'send_email', 'first_func_or_default',
|
|
106
108
|
'sort_by_keys', 'sort_by_values', 'Settings', 'load_yaml_file', 'Deployment', 'Version',
|
|
107
109
|
'sfield', 'field', 'upsert_df_data', 'upsert_deletor', 'get_row_versions', 'get_versions',
|
|
108
|
-
'db_to_value', 'upsert_data', 'upsert_selector', 'get_sfield_columns', 'filter_to_sfield_dict'
|
|
110
|
+
'db_to_value', 'upsert_data', 'upsert_selector', 'get_sfield_columns', 'filter_to_sfield_dict',
|
|
111
|
+
'SETTINGS', 'add_missing_enum_values']
|
ecodev_core/db_upsertion.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Module handling CRUD and version operations
|
|
3
3
|
"""
|
|
4
4
|
from datetime import datetime
|
|
5
|
+
from enum import EnumType
|
|
5
6
|
from functools import partial
|
|
6
7
|
from typing import Any
|
|
7
8
|
from typing import Union
|
|
@@ -14,6 +15,7 @@ from sqlmodel import inspect
|
|
|
14
15
|
from sqlmodel import select
|
|
15
16
|
from sqlmodel import Session
|
|
16
17
|
from sqlmodel import SQLModel
|
|
18
|
+
from sqlmodel import text
|
|
17
19
|
from sqlmodel import update
|
|
18
20
|
from sqlmodel.main import SQLModelMetaclass
|
|
19
21
|
from sqlmodel.sql.expression import SelectOfScalar
|
|
@@ -27,6 +29,31 @@ INFO = 'info'
|
|
|
27
29
|
SA_COLUMN_KWARGS = 'sa_column_kwargs'
|
|
28
30
|
|
|
29
31
|
|
|
32
|
+
def add_missing_enum_values(enum: EnumType, session: Session, new_vals: list | None = None) -> None:
|
|
33
|
+
"""
|
|
34
|
+
Add to an existing enum its missing db values. Do so by retrieving what is already in db, and
|
|
35
|
+
insert what is new
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
for val in [e.name for e in new_vals or enum if e.name not in get_enum_values(enum, session)]:
|
|
39
|
+
session.execute(text(f"ALTER TYPE {enum.__name__.lower()} ADD VALUE IF NOT EXISTS '{val}'"))
|
|
40
|
+
session.commit()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def get_enum_values(enum: EnumType, session: Session) -> set[str]:
|
|
44
|
+
"""
|
|
45
|
+
Return all enum values in db for the passed enum.
|
|
46
|
+
"""
|
|
47
|
+
result = session.execute(text(
|
|
48
|
+
"""
|
|
49
|
+
SELECT enumlabel FROM pg_enum
|
|
50
|
+
JOIN pg_type ON pg_enum.enumtypid = pg_type.oid
|
|
51
|
+
WHERE pg_type.typname = :enum_name
|
|
52
|
+
"""
|
|
53
|
+
), {'enum_name': enum.__name__.lower()})
|
|
54
|
+
return {x[0] for x in result}
|
|
55
|
+
|
|
56
|
+
|
|
30
57
|
def sfield(**kwargs):
|
|
31
58
|
"""
|
|
32
59
|
Field constructor for columns not to be versioned. Those are the columns on which to select.
|
|
@@ -147,11 +174,11 @@ def get_sfield_columns(db_model: SQLModelMetaclass) -> list[str]:
|
|
|
147
174
|
for x in inspect(db_model).c
|
|
148
175
|
if x.info.get(FILTER_ON) is True
|
|
149
176
|
]
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
def filter_to_sfield_dict(row: dict | SQLModelMetaclass,
|
|
153
|
-
|
|
154
|
-
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def filter_to_sfield_dict(row: dict | SQLModelMetaclass,
|
|
180
|
+
db_schema: SQLModelMetaclass | None = None) \
|
|
181
|
+
-> dict[str, dict | SQLModelMetaclass]:
|
|
155
182
|
"""
|
|
156
183
|
Returns a dict with only sfields from object
|
|
157
184
|
Args:
|
|
@@ -162,4 +189,3 @@ def filter_to_sfield_dict(row: dict | SQLModelMetaclass,
|
|
|
162
189
|
"""
|
|
163
190
|
return {pk: getattr(row, pk)
|
|
164
191
|
for pk in get_sfield_columns(db_schema or row.__class__)}
|
|
165
|
-
|
ecodev_core/settings.py
CHANGED
|
@@ -10,11 +10,8 @@ from pydantic_settings import SettingsConfigDict
|
|
|
10
10
|
|
|
11
11
|
from ecodev_core.deployment import Deployment
|
|
12
12
|
from ecodev_core.list_utils import dict_to_class
|
|
13
|
-
from ecodev_core.logger import logger_get
|
|
14
13
|
from ecodev_core.read_write import load_yaml_file
|
|
15
14
|
|
|
16
|
-
log = logger_get(__name__)
|
|
17
|
-
|
|
18
15
|
|
|
19
16
|
class DeploymentSetting(BaseSettings):
|
|
20
17
|
"""
|
|
@@ -43,9 +40,7 @@ class Settings:
|
|
|
43
40
|
information coming from a secret file.
|
|
44
41
|
"""
|
|
45
42
|
self.deployment = deployment
|
|
46
|
-
|
|
47
43
|
with suppress(FileNotFoundError):
|
|
48
|
-
log.info((base_path / 'config' / f'{deployment.value}.yaml').exists())
|
|
49
44
|
data = load_yaml_file(base_path / 'config' / f'{deployment.value}.yaml')
|
|
50
45
|
if (secrets_file := base_path / 'secrets' / f'{deployment.value}.yaml').exists():
|
|
51
46
|
data = deep_update(data, load_yaml_file(secrets_file))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
ecodev_core/__init__.py,sha256=
|
|
1
|
+
ecodev_core/__init__.py,sha256=UgK7wYtjjqjhAN772FlxiY16FkwvjbBdKUgAFGKggBs,6089
|
|
2
2
|
ecodev_core/app_activity.py,sha256=KBtI-35LBLPDppFB7xjxWthXQrY3Z_aGDnC-HrW8Ea0,4641
|
|
3
3
|
ecodev_core/app_rights.py,sha256=RZPdDtydFqc_nFj96huKAc56BS0qS6ScKv4Kghqd6lc,726
|
|
4
4
|
ecodev_core/app_user.py,sha256=r1bqA4H08x53XmxmjwyGKl_PFjYQazzBbVErdkztqeE,2947
|
|
@@ -11,7 +11,7 @@ ecodev_core/db_connection.py,sha256=hhqeyTrl0DlQA7RkUs6pIOpZeE3yS_Q5mqj5uGPfG_Y,
|
|
|
11
11
|
ecodev_core/db_filters.py,sha256=T_5JVF27UEu7sC6NOm7-W3_Y0GLfbWQO_EeTXcD2cv8,5041
|
|
12
12
|
ecodev_core/db_insertion.py,sha256=k-r798MMrW1sRb-gb8lQTxyJrb4QP5iZT8GDzCYYwlo,4544
|
|
13
13
|
ecodev_core/db_retrieval.py,sha256=sCP7TDGIcTOK5gT3Inga91bE4S31HbQPw4yI22WJbss,7392
|
|
14
|
-
ecodev_core/db_upsertion.py,sha256=
|
|
14
|
+
ecodev_core/db_upsertion.py,sha256=Pdu_LkcgePygICM3flfOIADHbL_NRUOC6WqAh-p3YcI,6757
|
|
15
15
|
ecodev_core/deployment.py,sha256=z8ACI00EtKknXOB8xyPwYIXTvPjIDOH9z9cBGEU0YrA,281
|
|
16
16
|
ecodev_core/email_sender.py,sha256=V3UGweuq6Iy09Z9to8HzM6JOVDVGHZXHGjUSkW94Tac,1912
|
|
17
17
|
ecodev_core/enum_utils.py,sha256=BkQ4YQ97tXBYmMcQiSIi0mbioD5CgVU79myg1BBAXuA,556
|
|
@@ -23,10 +23,10 @@ ecodev_core/permissions.py,sha256=WAx-ilMu8LlQp2sjJVdkhNQieytEaEm8577ZF1HWeTY,50
|
|
|
23
23
|
ecodev_core/pydantic_utils.py,sha256=e3GH50JmcpTmd2UgrB94QSwWOlOCW3WIlVdyX9C4T-U,741
|
|
24
24
|
ecodev_core/read_write.py,sha256=YIGRERvFHU7vy-JIaCWAza4CPMysLRUHKJxN-ZgFmu0,1208
|
|
25
25
|
ecodev_core/safe_utils.py,sha256=Q8N15El1tSxZJJsy1i_1CCycuBN1_98QQoHmYJRcLIY,6904
|
|
26
|
-
ecodev_core/settings.py,sha256=
|
|
26
|
+
ecodev_core/settings.py,sha256=UvaTv8S_HvfFAL-m1Rfqv_geSGcccuV3ziR1o1d5wu4,1795
|
|
27
27
|
ecodev_core/sqlmodel_utils.py,sha256=t57H3QPtKRy4ujic1clMK_2L4p0yjGJLZbDjHPZ8M94,453
|
|
28
28
|
ecodev_core/version.py,sha256=eyIf8KkW_t-hMuYFIoy0cUlNaMewLe6i45m2HKZKh0Q,4403
|
|
29
|
-
ecodev_core-0.0.
|
|
30
|
-
ecodev_core-0.0.
|
|
31
|
-
ecodev_core-0.0.
|
|
32
|
-
ecodev_core-0.0.
|
|
29
|
+
ecodev_core-0.0.53.dist-info/LICENSE.md,sha256=8dqVJEbwXjPWjjRKjdLMym5k9Gi8hwtrHh84sti6KIs,1068
|
|
30
|
+
ecodev_core-0.0.53.dist-info/METADATA,sha256=J57EVk_FfORxTLvYXjn7KLrN8p98J0K4C8tMGyixab4,3509
|
|
31
|
+
ecodev_core-0.0.53.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
32
|
+
ecodev_core-0.0.53.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|