
    Oj	                        d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZ e j                            d  e ee                                          j        j                             d dlmZ d dlmZ ej        Zej        re                    d	ej                   ej         eej                   ej        Z ee          ZddZddZddZ  ej!                    r e             dS  e              dS )    N)
fileConfig)Path)context)engine_from_configpool)
get_logger)settings)Basesqlalchemy.urlreturnc                    ddl m} ddlm} |                      |d                    }d |D             }|                                }|sd S |D ]}	 |                     d |i          }t          j        	                    ||d           |                      |d	                     \# t          $ rL}t                              |
                              d                              d           Y d }~d }~ww xY wd S )Nr   )text)TenantSchemaManagerzUSELECT schema_name FROM information_schema.schemata WHERE schema_name LIKE 'tenant_%'c                     g | ]
}|d          S )r    ).0rows     3/lsinfo/ai/hellotax_ai/base_platform/alembic/env.py
<listcomp>z(_sync_tenant_schemas.<locals>.<listcomp>    s    ///c!f///    )schema_translate_mapT)bindtables
checkfirstCOMMIT)schema)	exceptionzFailed to sync schema)
sqlalchemyr   app.db.tenant_schemar   executeget_tenant_table_definitionsexecution_optionsr
   metadata
create_all	Exceptionloggerr   opterror)	
connectionr   r   resulttenant_schemastenant_tablesschema_nametenant_bindes	            r   _sync_tenant_schemasr0      sb   888888c	
 	
 F
 0////N'DDFFM % _ _	_$66TS^L_6``KM$$+mX\$]]]ttH~~.... 	_ 	_ 	_KK{K++//$/??EEF]^^^^^^^^	__ _s   AB--
D7AC>>Dc                      t                               d          } t          j        | t          dddidd           t          j                    5  t          j                     d d d            d S # 1 swxY w Y   d S )Nr   T
paramstylenamed)urltarget_metadataliteral_bindsdialect_optscompare_typecompare_server_default)configget_main_optionr   	configurer5   begin_transactionrun_migrations)r4   s    r   run_migrations_offliner?   -   s    

 
 !1
2
2C'"G,#    
	"	$	$ ! !   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !s   A00A47A4c                     t          t                              t          j        i           dt          j                  } |                                 5 }t          j        |t          dd           t          j
                    5  t          j                     d d d            n# 1 swxY w Y   t          |           d d d            d S # 1 swxY w Y   d S )Nzsqlalchemy.)prefix	poolclassT)r)   r5   r8   r9   )r   r:   get_sectionconfig_ini_sectionr   NullPoolconnectr   r<   r5   r=   r>   r0   )connectabler)   s     r   run_migrations_onlinerH   ;   sR   $64b99-  K
 
				 	)*!+#'		
 	
 	
 	
 &(( 	% 	%"$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%Z(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s6   1CB%C%B)	)C,B)	-CCC)r   N)"syslogging.configr   pathlibr   alembicr   r   r   r   common_loggingr   pathinsertstr__file__resolveparent
app.configr	   app.db.baser
   r:   DATABASE_URLset_main_optionconfig_file_namer#   r5   __name__r&   r0   r?   rH   is_offline_moder   r   r   <module>r[      s   



 % % % % % %             / / / / / / / / % % % % % % 33ttH~~--//6=>> ? ? ?            	 D
+X-BCCC	&Jv&'''-	H		_ _ _ _.! ! ! !) ) ) )$ 7 r   