
    yj                     j   d dl Z d dlZd dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZmZ d dlmZ d dlmZ d dlZ e j                      e j        d	                              e j                    e j        d
                              e j                   ej                             e ee          j        d                              e
j        Zej         eej        d           ej         Z!defdZ"ddZ#dedefdZ$ddZ% e
j&                    r e#             dS  e%             dS )    N)
fileConfig)Path)urlparse
urlunparse)context)engine_from_configtext)settings)Basezsqlalchemy.enginealembic   F)disable_existing_loggersreturnc                  J    t           j        j        } | t          d          | S )NzDB_CONNECTION_URI not set)r
   DBCONNECTION_URI
ValueErrorurls    6/DATA/AppData/hermes/projects/honcho/migrations/env.pyget_urlr   0   s%    
+
$C
{4555J    c                  P   t          t                                } t          j        | t          dddit          j                   t          j                    5  t          j        dt          j                    t          j                     ddd           dS # 1 swxY w Y   dS )aF  Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    T
paramstylenamed)r   target_metadataliteral_bindsdialect_optsversion_table_schemaSET search_path TO N)	ensure_session_poolerr   r   	configurer   schemabegin_transactionexecuterun_migrationsr   s    r   run_migrations_offliner'   7   s      		
*
*C'"G,,3    
	"	$	$ ! !Fo.DFFGGG   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !s   5BB"Bconnection_uric                     t          |           }|j        pd}|dk    rU|j        r|j                            d| d          }n
|j         d}|                    |          }t          |          S | S )a  
    Ensure a PostgreSQL connection URI uses the session pooler port (5432).

    Converts transaction pooler port (6543) to session pooler port (5432).
    Leaves other ports unchanged.

    Args:
        connection_uri: PostgreSQL connection URI

    Returns:
        Connection URI with session pooler port (5432)

    Examples:
        >>> ensure_session_pooler("postgresql://user:pass@host:6543/db")
        'postgresql://user:pass@host:5432/db'

        >>> ensure_session_pooler("postgresql://user:pass@host:5432/db")
        'postgresql://user:pass@host:5432/db'

        >>> ensure_session_pooler("postgresql+psycopg://user:pass@host.supabase.co:6543/postgres")
        'postgresql+psycopg://user:pass@host.supabase.co:5432/postgres'
    i8  i  :z:5432)netloc)r   portr+   replace_replacer   )r(   parsedcurrent_port
new_netloc
new_parseds        r   r!   r!   R   s    . n%%F ;&$L t; 	1../A</A/A7KKJJ #M000J __J_77
*%%%r   c                  z   t                               t           j                  } | i } t                      }t	          |          }|| d<   t          | ddddd          }|                                5 }|                    t          dt          j
         d	                     |                    t          d
t          j
         d                     |                    t          d                     |                    t          dt          j
         d                     |                                 t          j        |t          t          j
        dd            t          j                    5  t          j                     ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )zRun migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    Nzsqlalchemy.urlzsqlalchemy.Fz-c statement_timeout=300000)prepare_thresholdoptions)prefixechoconnect_argszCREATE SCHEMA IF NOT EXISTS ;zGRANT ALL ON SCHEMA z TO current_userz%CREATE EXTENSION IF NOT EXISTS vectorr    z, public, extensionsTc                 d    t          | d          rt          | dd           t          j        k    ndS )Nr#   T)hasattrgetattrr   r#   )objnametype_	reflected
compare_tos        r   <lambda>z'run_migrations_online.<locals>.<lambda>   s7     3))Xt,,0FFF	 r   )
connectionr   r   include_schemasinclude_object)configget_sectionconfig_ini_sectionr   r!   r   connectr%   r	   r   r#   commitr   r"   r$   r&   )configurationr   validated_urlconnectablerC   s        r   run_migrations_onlinerN      s[    &&v'@AAM
))C)#..M&3M"#$!%4
 
	  K 
				 %*I0FIIIJJ	
 	
 	
 	P(>PPPQQ	
 	
 	
 	4 GHHIIIS'=SSSTT	
 	
 	
 	!+!0!7  	
 	
 	
 	
 &(( 	% 	%"$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%;% % % % % % % % % % % % % % % % % %s7   5DF08FF0F	F0F	 F00F47F4)r   N)'loggingsyslogging.configr   pathlibr   urllib.parser   r   r   r   
sqlalchemyr   r	   
src.configr
   src.dbr   
src.modelssrcbasicConfig	getLoggersetLevelINFODEBUGpathappendstr__file__parentsrF   config_file_namemetadatar   r   r'   r!   rN   is_offline_mode r   r   <module>rg      s    



 % % % % % %       - - - - - - - -       / / / / / / / /                       % & & / / = = =  )   % %gm 4 4 4 DDNN*1-.. / / / 
 
&Jv&GGGG -    ! ! ! !6*# *# * * * *Z8% 8% 8% 8%v 7 r   