
    ,hy                      .   S SK Jr  S SK Jr  S SK Jr  S SKJr  S SKJr  S SKJ	r	  S SKJ
r
  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  \	R*                  " S5      S 5       r\R*                  " S5      S 5       rS r\R*                  " S5      S 5       r\
R*                  " S5      S 5       r\R*                  " S5      S 5       r\R*                  " S5      S 5       rS"S jr\" 5       r\R*                  " S5      S 5       r \R*                  " S5      S 5       r!\R*                  " S5      S 5       r"\R*                  " S5      S 5       r#\R*                  " S5      S  5       r$\R*                  " S5      S! 5       r%g)#   )create_engine)exc)inspect)url)configure_follower)	create_db)#drop_all_schema_objects_post_tables)"drop_all_schema_objects_pre_tables)drop_db)follower_url_from_main)log)post_configure_engine)run_reap_dbs) set_default_schema_on_connection) stop_test_class_outside_fixtures)temp_table_keyword_args)update_db_optsoraclec                    UR                  5        nUR                  SU-  5        UR                  SU-  5        UR                  SU-  5        UR                  SU< 35        UR                  SU-  5        UR                  SU-  5        UR                  SU-  5        UR                  SU-  5        UR                  S	U-  5        UR                  S
U-  5        S S S 5        g ! , (       d  f       g = f)Nzcreate user %s identified by xez#create user %s_ts1 identified by xez#create user %s_ts2 identified by xezgrant dba to z grant unlimited tablespace to %sz$grant unlimited tablespace to %s_ts1z$grant unlimited tablespace to %s_ts2zgrant create table to %szgrant create table to %s_ts1zgrant create table to %s_ts2)beginexec_driver_sqlcfgengidentconns       \/var/www/auris/envauris/lib/python3.13/site-packages/sqlalchemy/dialects/oracle/provision.py_oracle_create_dbr      s    
 
>FGBUJKBUJK%9:?%GHCeKLCeKL7%?@;eCD;eCD 
s   C
C$$
C2c                 ,    SU-  U l         SU-  U l        g N%s_ts1%s_ts2)test_schematest_schema_2)configr   s     r   _oracle_configure_followerr&   /   s    !E)F#e+F    c                      U R                  SU-  5        [        R                  " SU5        g! [        R                   a!  n[        R
                  " SU5         S nAgS nAff = f)Nzdrop user %s cascadezReaped db: %sTzcouldn't drop db: %sF)r   r   infor   DatabaseErrorwarning)r   dbnameerrs      r   _ora_drop_ignorer.   5   sT    3f<=&) *C0s   +. A#AA#c                 D    [        U5        [        XR                  5        g N)_purge_recyclebinr#   r   r   s     r   '_ora_drop_all_schema_objects_pre_tablesr3   ?   s    cc??+r'   c           	         UR                  5        nUR                  R                  US S S 5       H  nUR                  SUS    35        M     UR                  R                  X R                  S S 5       H'  nUR                  SU R                   SUS    35        M)     [        U5      R                  5        H  nUR                  SU 35        M     S S S 5        g ! , (       d  f       g = f)Nzdrop synonym synonym_name.zdrop table )r   dialect_get_synonymsr   r#   r   get_temp_table_names)r   r   r   syn	tmp_tables        r   (_ora_drop_all_schema_objects_post_tablesr<   E   s    	<<--dD$EC  =^1D0E!FG F <<--//4
C   0#n2E1FG
 !;;=I  ;yk!:; > 
s   CC
C+c                     UR                  5        n[        X25        [        USU-  5        [        USU-  5        S S S 5        g ! , (       d  f       g = fr    )r   r.   r   s       r   _oracle_drop_dbr>   V   s?    	 	%x%/0x%/0 
s   *A
Ac                 X    [        U5        [
         H  n UR                  nSUl        XTl        M     [
        R                  5         g ! [        R                   a!  n[        R                  " SU5         S nANlS nAff = f! UR                  R                  R                   a     M  f = f)Nz#purge recyclebin command failed: %s    )r1   r   r*   r   r+   
_all_connsstmtcachesizer7   dbapiInterfaceErrorclear)r%   dbclsr-   cx_oracle_connscs         r   %_ora_stop_test_class_outside_fixturesrJ   c   s    @" %	.--B
 ,-N(+-( %   @93??@ zz.. 		s(   A	 B	A>A99A>$B)(B)Nc                 B   U R                  5        nUc  UR                  S5        O`UR                  SSUR                  R                  U5      05      R	                  5        H!  u  p4nUR                  SU SU SU S35        M#     S S S 5        g ! , (       d  f       g = f)Nzpurge recyclebinzWselect owner, object_name,type from dba_recyclebin where owner=:schema and type='TABLE'schemazpurge  z."")r   r   r7   denormalize_nameall)r   rL   r   ownerobject_nametype_s         r   r1   r1   y   s    	>   !34 .2-A-AF4<<88@A. ce	.)E
 $$veWAeWB{m1%MN. 
s   A6B
Bc                 p    SSK Jn  UR                  US5      S 5       nUR                  US5      S 5       ng )Nr@   )eventcheckoutc                 .    [         R                  U 5        g r0   )rA   add)	dbapi_con
con_record	con_proxys      r   rV   /_oracle_post_configure_engine.<locals>.checkout   s    y!r'   checkinc                 F    SUR                   ;   a  UR                  5         g g )Ncx_oracle_xid)r)   
invalidate)dbapi_connectionconnection_records     r   r]   ._oracle_post_configure_engine.<locals>.checkin   s$    
 /444((* 5r'   )
sqlalchemyrU   listens_for)r   enginefollower_identrU   rV   r]   s         r   _oracle_post_configure_enginerh      sE     
vz*" +" vy)+ *+r'   c                    [         R                  " SU 5        [        U 5      nUR                  5        n[         R                  " SSR	                  U5      5        UR                  S5      nU Vs1 s H  u  oUR                  5       iM     nn[        5       nU H  nUR                  S5      (       d  UR                  S5      (       a  M1  X;   d  M8  UR                  U5        SU-  U;   a  UR                  SU-  5        SU-  U;   d  Mq  UR                  SU-  5        M     S	=p[        US
5       H  u  p[        X55      (       d  M  U	S
-  n	M     [         R                  " SX5        S S S 5        g s  snf ! , (       d  f       g = f)Nzdb reaper connecting to %rzidentifiers in file: %sz, zselect u.username from all_users u where username like 'TEST_%' and not exists (select username from v$session where username=u.username)_ts1_ts2r!   r"   r@      z-Dropped %d out of %d stale databases detected)r   r)   r   r   joinr   lowersetendswithrX   	enumerater.   )r   identsr   r   to_reapusername	all_namesto_dropnamedroppedtotals              r   _reap_oracle_dbsrz      sD   HH)3/

C	*DIIf,=>&&8

 :AA+8^^%	A%D}}V$$f(=(=D!d?i/KK40d?i/KK40  (!4OE//1  5 	;W	
1 
 B 
s0   <E5/E0
AE55E5	:E5 E50E55
Fc                 N    [         R                  " U 5      n U R                  USS9$ )Nxe)rt   password)sa_urlmake_urlro   )r   r   s     r   _oracle_follower_url_from_mainr      s#    
//#
C77ED711r'   c                     S/SS.$ )NzGLOBAL TEMPORARYzPRESERVE ROWS)prefixesoracle_on_commit r2   s     r   _oracle_temp_table_keyword_argsr      s     ((+ r'   c                 l    UR                  5       nUR                  SU-  5        UR                  5         g )Nz#ALTER SESSION SET CURRENT_SCHEMA=%s)cursorexecuteclose)r   ra   schema_namer   s       r   (_oracle_set_default_schema_on_connectionr      s-     $$&F
NN8;FG
LLNr'   c                     UR                   (       a/  [        R                  " U 5      R                  5       S:X  a  SUS'   ggg)zCSet database options (db_opts) for a test database that we created.oracledbT
thick_modeN)oracledb_thick_moder~   r   get_driver_name)db_urldb_optsoptionss      r   _update_db_optsr      s<     	##OOF#335C $ D 	$r'   r0   )& r   r   r   rf   r   r~   testing.provisionr   r   r	   r
   r   r   r   r   r   r   r   r   r   for_dbr   r&   r.   r3   r<   r>   rJ   r1   ro   rA   rh   rz   r   r   r   r   r   r'   r   <module>r      s      # 3 * D C ( 7 $ 6 - A A 8 / (E E$ 8$, %,
 $**84, 5,
 %++H5< 6<  		1 	1 "((2 3*O  U
 h'+ (+  X
 
@ x(2 )2
 ) * "((2 3 x % !%r'   