Spaces:
Paused

File size: 1,691 Bytes
357bfdf
8eb630b
 
 
 
579285c
8eb630b
 
 
357bfdf
a68a275
8eb630b
 
0743ddc
 
357bfdf
8eb630b
 
357bfdf
579285c
 
 
 
 
 
 
 
 
 
 
 
 
0743ddc
579285c
 
 
 
 
 
357bfdf
8eb630b
 
a68a275
 
8eb630b
 
579285c
8eb630b
 
 
 
 
 
357bfdf
8eb630b
 
 
357bfdf
8eb630b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Platform Database Module
Core database infrastructure for YAZ Care Platform

Exports:
- ID Generation: PlatformID, new_uuid7
- Models: User (as CoreUser), Tenant, UserRole
- Mixins: TenantMixin, TimestampMixin, SoftDeleteMixin
- Sessions: get_db_session, get_async_session
"""

# Import session factories from manager
from .manager import get_db_session
from .mixins import SoftDeleteMixin, TenantMixin, TimestampMixin, UserTrackingMixin
from .platform_id import PlatformID, new_uuid7

# Alias for compatibility
get_async_session = get_db_session

# CoreUser / Tenant are lazy-loaded so pytest --import-mode=importlib never trips
# on "shared.models" not being on sys.path at collection time.  The first genuine
# access (e.g. `from core.database import CoreUser`) triggers the real import.
_LAZY: dict[str, tuple[str, str]] = {
    "CoreUser": ("shared.models.user", "User"),
    "Tenant": ("shared.models.tenant", "Tenant"),
}


def __getattr__(name: str):
    if name in _LAZY:
        module_path, attr = _LAZY[name]
        import importlib as _il

        mod = _il.import_module(module_path)
        val = getattr(mod, attr)
        globals()[name] = val  # cache so subsequent lookups skip __getattr__
        return val
    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


# Import UserRole enum from feature_flags
from core.feature_flags.enums import UserRole

__all__ = [
    # ID Generation
    "PlatformID",
    "new_uuid7",
    # Mixins
    "TenantMixin",
    "TimestampMixin",
    "SoftDeleteMixin",
    "UserTrackingMixin",
    # Sessions
    "get_db_session",
    "get_async_session",
    # Models
    "CoreUser",
    "Tenant",
    "UserRole",
]