
    i#                        d Z ddlmZ ddlmZ ddlmZ ddlmZmZm	Z	m
Z
mZ ddlmZmZmZ  G d de      Z G d	 d
e      Z G d de      Z G d de      Zy)u  
SQLAlchemy ORM models for profiling storage (dbo schema).

- **user_profiling** — published data (admin API reads this only). One row per user_id.
- **user_profiling_staging** — batch job writes here; a full successful scan ends with
  :meth:`ProfilingRepository.publish_staging_to_published` (single transaction).

Other app code (data_fetcher, deep analysis) stays on raw SQL + pyodbc.
    )annotations)datetime)Optional)
BigIntegerDateTimeIdentityUnicodeTexttext)DeclarativeBaseMappedmapped_columnc                      e Zd Zy)BaseN)__name__
__module____qualname__     ?/var/www/html/userprofiledev.eatanceapp.com/storage/db_model.pyr   r      s    r   r   c                      e Zd ZU dZdZddiZ ee e       d      Z	de
d<    eed	d
      Zde
d<    e ed	      d	 ed            Zde
d<    eed	      Zde
d<    eed      Zde
d<   y)UserProfilinga  
    Published snapshot. Admin/API reads dbo.user_profiling.

    Legacy/production tables often use ``id`` BIGINT IDENTITY as PK and ``user_id`` as
    a separate column (possibly multiple historical rows per user until deduped).
    Upserts use raw MERGE in :class:`ProfilingRepository` so ``id`` is generated by SQL Server.

    Staging uses ``updated_at``; publish MERGE maps staging timestamps into ``created_at``.
    user_profilingschemadboTprimary_keyMapped[int]idF)nullableindexuser_idtimezoneSYSUTCDATETIME()r   server_defaultMapped[datetime]
created_atr   Mapped[str]profile_jsonMapped[Optional[str]]deep_analysis_markdownN)r   r   r   __doc____tablename____table_args__r   r   r   r   __annotations__r!   r   r
   r(   r	   r+   r-   r   r   r   r   r      s     %M&N#J
MBM(e4PG[P#0% ./$J  
 !.kE JL+J4A+X\4]1]r   r   c                      e Zd ZU dZdZddiZ eedd      Zde	d	<    e e
d
      d ed            Zde	d<    eed      Zde	d<    eed      Zde	d<   y)UserProfilingStagingzm
    Batch refresh workspace. Not read by admin API until publish.
    Table: dbo.user_profiling_staging
    user_profiling_stagingr   r   TF)r   autoincrementr   r!   r"   r$   r%   r'   
updated_atr)   r*   r+   r,   r-   N)r   r   r   r.   r/   r0   r   r   r!   r1   r   r
   r6   r	   r+   r-   r   r   r   r3   r3   1   s{    
 -M&N )UZ[G[[#0% ./$J  
 !.kE JL+J4A+X\4]1]r   r3   c                      e Zd ZU dZdZddiZ ee e       d      Z	de
d<    eed	d
      Zde
d<    e ed	      d	      Zde
d<   y)UserProfilingTrackerz
    Last successful *published* run per user (batch recency skip).

    Surrogate ``id`` IDENTITY + unique ``user_id`` matches SQL Server-friendly layout and
    avoids ORM IDENTITY_INSERT on a non-identity ``user_id`` PK.
    user_profiling_trackerr   r   Tr   r   r   F)r   uniquer!   r"   r)   r'   last_completed_atN)r   r   r   r.   r/   r0   r   r   r   r   r1   r!   r   r;   r   r   r   r8   r8   E   s^     -M&N#J
MBM(eDQG[Q*7% +' r   r8   N)r.   
__future__r   r   typingr   
sqlalchemyr   r   r   r	   r
   sqlalchemy.ormr   r   r   r   r   r3   r8   r   r   r   <module>r@      sU    #   H H A A	? 	^D ^2^4 ^(4 r   