
    gy                      ,   d dl mZ d dl mZ d dl mZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ  e	j*                  d      d        Z ej*                  d      d        Zd Z ej*                  d      d        Z e
j*                  d      d        Z ej*                  d      d        Z ej*                  d      d        Zd"dZ e       Z ej*                  d      d        Z  ej*                  d      d        Z! ej*                  d      d        Z" ej*                  d      d        Z# ej*                  d      d         Z$ ej*                  d      d!        Z%y)#   )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                    |j                         5 }|j                  d|z         |j                  d|z         |j                  d|z         |j                  d|       |j                  d|z         |j                  d|z         |j                  d|z         |j                  d|z         |j                  d	|z         |j                  d
|z         d d d        y # 1 sw Y   y xY w)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       c/var/www/html/AdoubleTech/venv/lib/python3.12/site-packages/sqlalchemy/dialects/oracle/provision.py_oracle_create_dbr      s    
 
 E>FGBUJKBUJK%9:?%GHCeKLCeKL7%?@;eCD;eCDE E Es   C	C##C,c                 ,    d|z  | _         d|z  | _        y N%s_ts1%s_ts2)test_schematest_schema_2)configr   s     r   _oracle_configure_followerr&   /   s    !E)F#e+F    c                     	 | j                  d|z         t        j                  d|       y# t        j                  $ r }t        j
                  d|       Y d }~yd }~ww xY w)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                 F    t        |       t        || j                         y N)_purge_recyclebinr#   r   r   s     r   '_ora_drop_all_schema_objects_pre_tablesr3   ?   s    cc3??+r'   c           	         |j                         5 }|j                  j                  |d d d       D ]  }|j                  d|d            |j                  j                  || j                  d d       D ]&  }|j                  d| j                   d|d           ( t        |      j                         D ]  }|j                  d|         	 d d d        y # 1 sw Y   y xY w)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$E 	HC  =^1D0E!FG	H <<--#//4
 	C   0#n2E1FG	 !;;= 	<I  ;yk!:;	<< < <s   B>CC"c                     |j                         5 }t        ||       t        |d|z         t        |d|z         d d d        y # 1 sw Y   y xY wr    )r   r.   r   s       r   _oracle_drop_dbr>   V   sL    	 1 	u%x%/0x%/01 1 1s   +AAc                 N   	 t        |       t
        D ]  }	 |j                  }d|_        ||_         t
        j                          y # t        j                  $ r }t        j                  d|       Y d }~id }~ww xY w# |j                  j                  j                  $ r Y w xY w)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(+-N(.   @93??@ zz.. 		s(   A A>A;A66A;>#B$#B$Nc                 4   | j                         5 }||j                  d       n_|j                  dd|j                  j                  |      i      j	                         D ]!  \  }}}|j                  d| d| d| d       # d d d        y # 1 sw Y   y xY w)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    	 O>   !34 .2-A-AF4<<88@A. ce	O){E
 $$veWAeWB{m1%MNOO O Os   A4BBc                 p    ddl m} |j                  |d      d        }|j                  |d      d        }y )Nr@   )eventcheckoutc                 .    t         j                  |        y r0   )rA   add)	dbapi_con
con_record	con_proxys      r   rV   z/_oracle_post_configure_engine.<locals>.checkout   s    y!r'   checkinc                 B    d|j                   v r|j                          y y )Ncx_oracle_xid)r)   
invalidate)dbapi_connectionconnection_records     r   r\   z._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_enginerf      sE     
vz*" +" vy)+ *+r'   c                    t        j                  d|        t        |       }|j                         5 }t        j                  ddj	                  |             |j                  d      }|D ch c]  \  }|j                          }}t               }|D ]r  }|j                  d      s|j                  d      r&||v s+|j                  |       d|z  |v r|j                  d|z         d|z  |v s_|j                  d|z         t d	x}	}
t        |d
      D ]  \  }
}t        ||      s|	d
z  }	 t        j                  d|	|
       d d d        y c c}w # 1 sw Y   y xY w)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_dbsrx      s[   HH)3/

C	 
*DIIf,=>&&8

 :AA+8X^^%A	A% 	1D}}V$f(=D!d?i/KK40d?i/KK40	1 %(!4 	OE8h/1	 	;We	
1
 
 B
 
s/   ;E-E8E?3E38E,EEE!c                 R    t        j                  |       } | j                  |d      S )Nxe)rr   password)sa_urlmake_urlrm   )r   r   s     r   _oracle_follower_url_from_mainr~      s#    
//#
C77ED711r'   c                     dgddS )NzGLOBAL TEMPORARYzPRESERVE ROWS)prefixesoracle_on_commit r2   s     r   _oracle_temp_table_keyword_argsr      s     ((+ r'   c                 l    |j                         }|j                  d|z         |j                          y )Nz#ALTER SESSION SET CURRENT_SCHEMA=%s)cursorexecuteclose)r   r`   schema_namer   s       r   (_oracle_set_default_schema_on_connectionr      s-     $$&F
NN8;FG
LLNr'   c                 v    |j                   r-t        j                  |       j                         dk(  rd|d<   yyy)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   rd   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   rm   rA   rf   rx   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'   