Ë
    tPêjæ  ã                   ó~   — d Z ddlZddlZddlmZ ddlmZ dedee   fd„Z	dede
eee   f   fd	„Zddedz  ddfd
„Zy)zCModule for checking differences between Prisma schema and database.é    N)ÚFinal)Úverbose_loggerÚdiff_outputÚreturnc                 óâ  — | j                  d«      D �cg c]#  }|j                  «       sŒ|j                  «       ‘Œ% }}g }d}d}|D ]€  }|j                  d«      r(|r#|r!|j                  |j                  «       «       d}d}Œ<|sŒ?|j	                  d«      r)||z  }|j                  |j                  «       «       d}d}Œy||dz   z  }Œ‚ |r|j                  |j                  «       «       |S c c}w )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         úe/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/proxy/db/check_migration.pyÚextract_sql_commandsr   
   sð   € ð .9×->Ñ->¸tÓ-DÖU TÈÏ
É
Í�D—J‘J•LÐU€EÐUà€LØ€OØ€Làò .ˆØ�?‰?˜5Ô!Ù¡Ø×#Ñ# O×$9Ñ$9Ó$;Ô<Ø"$�Ø‰LÚØ�}‰}˜SÔ!Ø 4Ñ'�Ø×#Ñ# O×$9Ñ$9Ó$;Ô<Ø"$�Ø$‘à 4¨#¡:Ñ-‘ð.ñ  Ø×Ñ˜O×1Ñ1Ó3Ô4àÐùò3 Vs
   ”C,ªC,Údb_urlc           
      óz  — t        j                  d«       	 t        j                  dddd| dddgd	d	d	¬
«      }t	        |j
                  «      }|r,t        d«       t        d«       |D ]  }t        |«       Œ d	|fS dg fS # t        j                  $ r(}d|j                  › �}t        |«       dg fcY d}~S d}~ww xY w)a„  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.
    z"Checking for Prisma schema diff...Ú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)	r   ÚdebugÚ
subprocessÚrunr   ÚstdoutÚprintÚCalledProcessErrorÚstderr)r   Úresultr   ÚcommandÚeÚerror_messages         r   Úcheck_prisma_schema_diff_helperr+   /   sÖ   € ô ×ÑÐ=Ô>ðÜ"Ÿ™àØØØØØ'Ø!Øð	ð  ØØô
ˆô" 3°6·=±=ÓAˆáÜÐ1Ô2ÜÐ*Ô+Ø'ò �Ü�g•ðà˜Ð%Ð%à˜"�9ÐøÜ×(Ñ(ò Ø!KÈAÏHÉHÈ:ÐVˆÜˆmÔØ�bˆyÕûðús$   —A#A? Á;A? Á?B:ÂB5Â/B:Â5B:c                 óš   — | €"t        j                  d«      } | €t        d«      ‚t        | «      \  }}|rt	        j
                  d|«       yy)z2Main function to run the Prisma schema diff check.NÚDATABASE_URLzDATABASE_URL not setuh   ðŸš¨ðŸš¨ðŸš¨ prisma schema out of sync with db. Consider running these sql_commands to sync the two - %s)ÚosÚgetenvÚ	Exceptionr+   r   Ú	exception)r   Úhas_diffÚmessages      r   Úcheck_prisma_schema_diffr4   \   sQ   € à€~Ü—‘˜>Ó*ˆØˆ>ÜÐ2Ó3Ð3Ü7¸Ó?Ñ€HˆgÙÜ× Ñ ØvØõ	
ð ó    )N)Ú__doc__r.   r!   Útypingr   Úlitellm._loggingr   ÚstrÚlistr   ÚtupleÚboolr+   r4   © r5   r   ú<module>r>      sd   ðÙ Iã 	Û Ý å +ð" cð "¨d°3©ió "ðJ*¨Cð *°E¸$ÀÀSÁ	¸/Ñ4Jó *ñZ
 S¨4¡Zð 
¸4ô 
r5   