
    ^hl                         S r SSKrSSKrSSKJrJrJr  S\S\\   4S jrS\S\\	\\   4   4S jr
S
S\\   SS4S	 jjrg)zCModule for checking differences between Prisma schema and database.    N)ListOptionalTuplediff_outputreturnc                 4   U R                  S5       Vs/ s H)  oR                  5       (       d  M  UR                  5       PM+     nn/ nSnSnU H  nUR                  S5      (       a3  U(       a(  U(       a!  UR                  UR                  5       5        SnSnML  U(       d  MU  UR	                  S5      (       a)  XA-  nUR                  UR                  5       5        SnSnM  XAS-   -  nM     U(       a  UR                  UR                  5       5        U$ s  snf )z
Extract SQL commands from the Prisma migrate diff output.
Args:
    diff_output (str): The full output from prisma migrate diff.
Returns:
    List[str]: A list of SQL commands extracted from the diff output.

 Fz-- T; )splitstrip
startswithappendendswith)r   linelinessql_commandscurrent_commandin_sql_blocks         Z/home/james-whalen/.local/lib/python3.13/site-packages/litellm/proxy/db/check_migration.pyextract_sql_commandsr      s     '2&7&7&=N&=d\TZZ\&=ENLOL??5!!##O$9$9$;<"$L\}}S!!'##O$9$9$;<"$$#:-   O11343 Os
   DDdb_urlc           
      \    [         R                  " SSSSU SSS/SSSS	9n[        UR                  5      nU(       a.  [	        S
5        [	        S5        U H  n[	        U5        M     SU4$ S/ 4$ ! [         R
                   a(  nSUR                   3n[	        U5        S/ 4s SnA$ SnAff = f)ad  Checks for differences between current database and Prisma schema.
Returns:
    A tuple containing:
    - A boolean indicating if differences were found (True) or not (False).
    - A string with the diff output or error message.
Raises:
    subprocess.CalledProcessError: If the Prisma command fails.
    Exception: For any other errors during execution.
prismamigratediffz
--from-urlz--to-schema-datamodelz./schema.prismaz--scriptT)capture_outputtextcheckzChanges to DB Schema detectedzRequired SQL commands:Fz*Failed to generate migration diff. Error: N)
subprocessrunr   stdoutprintCalledProcessErrorstderr)r   resultr   commandeerror_messages         r   check_prisma_schema_diff_helperr+   -   s    '!	  
" ,FMM:12*+'g (%%"9(( DQXXJOmbys$   A(A/ +A/ /B+B& B+&B+c                     U c$  [         R                  " S5      n U c  [        S5      e[        U 5      u  pU(       a  [        SR	                  U5      5      eg)z2Main function to run the Prisma schema diff check.NDATABASE_URLzDATABASE_URL not setz[prisma schema out of sync with db. Consider running these sql_commands to sync the two - {})osgetenv	Exceptionr+   format)r   has_diffmessages      r   check_prisma_schema_diffr4   Y   sY    ~>*>2337?Hipp
 	
     )N)__doc__r.   r!   typingr   r   r   strr   boolr+   r4    r5   r   <module>r;      sd    I 	  ( ("c "d3i "J)C )E$S	/4J )X
Xc] 
d 
r5   