diracx-db 0.0.1a49__py3-none-any.whl → 0.0.1a50__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.
- diracx/db/sql/auth/schema.py +6 -2
- diracx/db/sql/utils/__init__.py +15 -11
- diracx/db/sql/utils/base.py +33 -1
- {diracx_db-0.0.1a49.dist-info → diracx_db-0.0.1a50.dist-info}/METADATA +1 -1
- {diracx_db-0.0.1a49.dist-info → diracx_db-0.0.1a50.dist-info}/RECORD +7 -7
- {diracx_db-0.0.1a49.dist-info → diracx_db-0.0.1a50.dist-info}/WHEEL +0 -0
- {diracx_db-0.0.1a49.dist-info → diracx_db-0.0.1a50.dist-info}/entry_points.txt +0 -0
diracx/db/sql/auth/schema.py
CHANGED
@@ -10,7 +10,12 @@ from sqlalchemy import (
|
|
10
10
|
)
|
11
11
|
from sqlalchemy.orm import declarative_base
|
12
12
|
|
13
|
-
from diracx.db.sql.utils import
|
13
|
+
from diracx.db.sql.utils import (
|
14
|
+
Column,
|
15
|
+
DateNowColumn,
|
16
|
+
EnumColumn,
|
17
|
+
NullColumn,
|
18
|
+
)
|
14
19
|
|
15
20
|
USER_CODE_LENGTH = 8
|
16
21
|
|
@@ -92,7 +97,6 @@ class RefreshTokens(Base):
|
|
92
97
|
status = EnumColumn(
|
93
98
|
"Status", RefreshTokenStatus, server_default=RefreshTokenStatus.CREATED.name
|
94
99
|
)
|
95
|
-
creation_time = DateNowColumn("CreationTime", index=True)
|
96
100
|
scope = Column("Scope", String(1024))
|
97
101
|
|
98
102
|
# User attributes bound to the refresh token
|
diracx/db/sql/utils/__init__.py
CHANGED
@@ -1,16 +1,6 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
|
4
|
-
BaseSQLDB,
|
5
|
-
SQLDBUnavailableError,
|
6
|
-
_get_columns,
|
7
|
-
apply_search_filters,
|
8
|
-
apply_sort_constraints,
|
9
|
-
)
|
10
|
-
from .functions import hash, substract_date, utcnow
|
11
|
-
from .types import Column, DateNowColumn, EnumBackedBool, EnumColumn, NullColumn
|
12
|
-
|
13
|
-
__all__ = (
|
3
|
+
__all__ = [
|
14
4
|
"_get_columns",
|
15
5
|
"utcnow",
|
16
6
|
"Column",
|
@@ -24,4 +14,18 @@ __all__ = (
|
|
24
14
|
"substract_date",
|
25
15
|
"hash",
|
26
16
|
"SQLDBUnavailableError",
|
17
|
+
"uuid7_from_datetime",
|
18
|
+
"uuid7_to_datetime",
|
19
|
+
]
|
20
|
+
|
21
|
+
from .base import (
|
22
|
+
BaseSQLDB,
|
23
|
+
SQLDBUnavailableError,
|
24
|
+
_get_columns,
|
25
|
+
apply_search_filters,
|
26
|
+
apply_sort_constraints,
|
27
|
+
uuid7_from_datetime,
|
28
|
+
uuid7_to_datetime,
|
27
29
|
)
|
30
|
+
from .functions import hash, substract_date, utcnow
|
31
|
+
from .types import Column, DateNowColumn, EnumBackedBool, EnumColumn, NullColumn
|
diracx/db/sql/utils/base.py
CHANGED
@@ -7,13 +7,15 @@ import re
|
|
7
7
|
from abc import ABCMeta
|
8
8
|
from collections.abc import AsyncIterator
|
9
9
|
from contextvars import ContextVar
|
10
|
-
from datetime import datetime
|
10
|
+
from datetime import datetime, timezone
|
11
11
|
from typing import Any, Self, cast
|
12
|
+
from uuid import UUID as StdUUID # noqa: N811
|
12
13
|
|
13
14
|
from pydantic import TypeAdapter
|
14
15
|
from sqlalchemy import DateTime, MetaData, func, select
|
15
16
|
from sqlalchemy.exc import OperationalError
|
16
17
|
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncEngine, create_async_engine
|
18
|
+
from uuid_utils import UUID, uuid7
|
17
19
|
|
18
20
|
from diracx.core.exceptions import InvalidQueryError
|
19
21
|
from diracx.core.extensions import select_from_extension
|
@@ -416,3 +418,33 @@ def apply_sort_constraints(column_mapping, stmt, sorts):
|
|
416
418
|
if sort_columns:
|
417
419
|
stmt = stmt.order_by(*sort_columns)
|
418
420
|
return stmt
|
421
|
+
|
422
|
+
|
423
|
+
def uuid7_to_datetime(uuid: UUID | StdUUID | str) -> datetime:
|
424
|
+
"""Convert a UUIDv7 to a datetime."""
|
425
|
+
if isinstance(uuid, StdUUID):
|
426
|
+
# Convert stdlib UUID to uuid_utils.UUID
|
427
|
+
uuid = UUID(str(uuid))
|
428
|
+
elif not isinstance(uuid, UUID):
|
429
|
+
# Convert string or other types to uuid_utils.UUID
|
430
|
+
uuid = UUID(uuid)
|
431
|
+
if uuid.version != 7:
|
432
|
+
raise ValueError(f"UUID {uuid} is not a UUIDv7")
|
433
|
+
return datetime.fromtimestamp(uuid.timestamp / 1000.0, tz=timezone.utc)
|
434
|
+
|
435
|
+
|
436
|
+
def uuid7_from_datetime(dt: datetime, *, randomize: bool = True) -> UUID:
|
437
|
+
"""Generate a UUIDv7 corresponding to the given datetime.
|
438
|
+
|
439
|
+
If randomize is True, the standard uuid7 function is used resulting in the
|
440
|
+
lowest 62-bits being random. If randomize is False, the UUIDv7 will be the
|
441
|
+
lowest possible UUIDv7 for the given datetime.
|
442
|
+
"""
|
443
|
+
timestamp = dt.timestamp()
|
444
|
+
if randomize:
|
445
|
+
uuid = uuid7(int(timestamp), int((timestamp % 1) * 1e9))
|
446
|
+
else:
|
447
|
+
time_high = int(timestamp * 1000) >> 16
|
448
|
+
time_low = int(timestamp * 1000) & 0xFFFF
|
449
|
+
uuid = UUID.from_fields((time_high, time_low, 0x7000, 0x80, 0, 0))
|
450
|
+
return uuid
|
@@ -8,7 +8,7 @@ diracx/db/os/utils.py,sha256=V4T-taos64SFNcorfIr7mq5l5y88K6TzyCj1YqWk8VI,11562
|
|
8
8
|
diracx/db/sql/__init__.py,sha256=JYu0b0IVhoXy3lX2m2r2dmAjsRS7IbECBUMEDvX0Te4,391
|
9
9
|
diracx/db/sql/auth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
10
|
diracx/db/sql/auth/db.py,sha256=QJtBqMrhOf97UvMG0WpyjsgIRiu19v04FoDzXAyXtT0,8952
|
11
|
-
diracx/db/sql/auth/schema.py,sha256=
|
11
|
+
diracx/db/sql/auth/schema.py,sha256=9fUV7taDPnoAcoiwRAmQraOmF2Ytoizjs2TFvN7zsVs,3132
|
12
12
|
diracx/db/sql/dummy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
13
|
diracx/db/sql/dummy/db.py,sha256=MKSUSJI1BlRgK08tjCfkCkOz02asvJAeBw60pAdiGV8,1212
|
14
14
|
diracx/db/sql/dummy/schema.py,sha256=9zI53pKlzc6qBezsyjkatOQrNZdGCjwgjQ8Iz_pyAXs,789
|
@@ -27,11 +27,11 @@ diracx/db/sql/sandbox_metadata/schema.py,sha256=V5gV2PHwzTbBz_th9ribLfE7Lqk8YGem
|
|
27
27
|
diracx/db/sql/task_queue/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
28
28
|
diracx/db/sql/task_queue/db.py,sha256=2qul1D2tX2uCI92N591WK5xWHakG0pNibzDwKQ7W-I8,6246
|
29
29
|
diracx/db/sql/task_queue/schema.py,sha256=5efAgvNYRkLlaJ2NzRInRfmVa3tyIzQu2l0oRPy4Kzw,3258
|
30
|
-
diracx/db/sql/utils/__init__.py,sha256=
|
31
|
-
diracx/db/sql/utils/base.py,sha256=
|
30
|
+
diracx/db/sql/utils/__init__.py,sha256=k1DI4Idlqv36pXn2BhQysb947Peio9DnYaePslkTpUQ,685
|
31
|
+
diracx/db/sql/utils/base.py,sha256=ZqqBYSKsRz2kLezOB7CSbxPFQVcozmaxNbrbXuGCKPs,16904
|
32
32
|
diracx/db/sql/utils/functions.py,sha256=_E4tc9Gti6LuSh7QEyoqPJSvCuByVqvRenOXCzxsulE,4014
|
33
33
|
diracx/db/sql/utils/types.py,sha256=KNZWJfpvHTjfIPg6Nn7zY-rS0q3ybnirHcTcLAYSYbE,5118
|
34
|
-
diracx_db-0.0.
|
35
|
-
diracx_db-0.0.
|
36
|
-
diracx_db-0.0.
|
37
|
-
diracx_db-0.0.
|
34
|
+
diracx_db-0.0.1a50.dist-info/METADATA,sha256=tF7YN-0vEiwoSOdb40_lPaZ5n191Tn5NaY_z3ifD2g4,675
|
35
|
+
diracx_db-0.0.1a50.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
36
|
+
diracx_db-0.0.1a50.dist-info/entry_points.txt,sha256=UPqhLvb9gui0kOyWeI_edtefcrHToZmQt1p76vIwujo,317
|
37
|
+
diracx_db-0.0.1a50.dist-info/RECORD,,
|
File without changes
|
File without changes
|