o
    ODi4                     @  s  U 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 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' Z(d e)d!< e
*ed"d#d$ Z+d%d& Z,e,Z-d'e)d(< d)Z.d'e)d*< G d+d, d,Z/G d-d. d.Z0G d/d0 d0Z1G d1d2 d2e1Z2G d3d4 d4e1Z3d)S )5    )annotations)Any)Dict)Set)CHAR)CheckConstraint)Column)event)
ForeignKey)Index)inspect)Integer)MetaData)Numeric)PrimaryKeyConstraint)String)Table)Text)text)UniqueConstraint   )autogenerate)util)api)_fk_spec)MigrationContextops)config)eq_)clear_staging_env)staging_envzSet[Any]names_in_this_testafter_parent_attachc                 C  s   t | j d S N)r"   addname)tableparent r)   `/var/www/Datamplify/venv/lib/python3.10/site-packages/alembic/testing/suite/_autogen_fixtures.py	new_table&   s   r+   c                 C  s   |dkr|t v S dS )Nr'   T)r"   )objr&   type_	reflected
compare_tor)   r)   r*   _default_include_object+   s   r0   r   _default_object_filtersN_default_name_filtersc                   @  s6   e Zd ZU dZdZded< edd Zedd ZdS )	ModelOneunique_constraint_reflectionNr   schemac              
   C  s   | j }t|d}td|tdtddtdtdtdttd	tdtd
d	 td|tdtddtdtddd td|tdtddtdtdddt	ddt
ddd td|tdttdttd |S )Nr6   useridTprimary_keyr&   2   a1pwpw_idxaddressemail_addressd   Fnullableorderorder_idamount      0rD   server_defaultzamount >= 0ck_order_amountr&   extraxuiduser.id)r6   r   r   r   r   r   r   r   r   r   r   r   r
   clsr6   mr)   r)   r*   _get_db_schema<   sH   


zModelOne._get_db_schemac              
   C  s   | j }t|d}td|tdtddtdtddd	td
tdd td|tdtddtdtddd	tdtdtddd td|tdtddtdtdddt	ddtdtt
dtddd td|tdtddtdtdtdtt
d td! |S )"Nr7   r8   r9   Tr:   r&   r<   FrC   r=   rP   )rL   r@   rA   rB   streetuq_emailrN   rE   rF   rG   
   rI   rJ   rK   user_idrR   zamount > -1rM   itemdescriptionzorder.order_idzlen(description) > 5)r6   r   r   r   r   r   r   r   r   r   r
   r   rS   r)   r)   r*   _get_model_schemai   sN   

	
zModelOne._get_model_schema)	__name__
__module____qualname____requires__r6   __annotations__classmethodrV   r]   r)   r)   r)   r*   r3   7   s   
 
,r3   c                   @  s@   e Zd ZdZddiZdddddd	Zed
d Zedd ZdS )NamingConvModelr4   conv_all_constraint_namesTzix_%(column_0_label)sz%uq_%(table_name)s_%(constraint_name)sz%ck_%(table_name)s_%(constraint_name)sz;fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)szpk_%(table_name)s)ixuqckfkpkc                 C  s  t  }td|tdttddtddd td|tdttdtdd	dtd
dd td|tdttdttdttddd td|tdttddd td|tdttdtdddtdttdttdddtdddtddd	 td|tdttdttdtd |S )Nx1qdb_x1_index_qdb_x1_primary_qrN   x2px1.qdb_x2_foreign_qq > 5db_x2_check_qx3rsdb_x3_unique_qx4db_x4_primary_qx5x4.qdb_x5_foreign_qdb_x5_primary_qdb_x5_unique_rs > 5db_x5_check_sunnamed_sqlite)	r   r   r   r   r   r   r
   r   r   )rT   rU   r)   r)   r*   rV      sb   






zNamingConvModel._get_db_schemac                 C  s
  ddl m} t| jd}td|tdtddtd d td|tdttd	td
t	ddd td|tdttdttdtt
dddt
d|dd td|tdtddtdd td|tdtddtd	tdtdttdtt
dddt	ddt	d|d	 |S )Nr   )conv)naming_conventionrk   rl   Tr:   ro   rp   rq   rs   token_x2check1rN   ru   rv   rw   	token_x3ruserdef_x3_unique_sry   userdef_x4_idx_qx6r|   	token_x6rr   token_x6check1zs < 20userdef_x6_check_s)sqlalchemy.sql.namingr   r   r   r   r   r   r   r
   r   r   )rT   r   rU   r)   r)   r*   r]      sN   

	
z!NamingConvModel._get_model_schemaN)	r^   r_   r`   ra   configure_optsr   rc   rV   r]   r)   r)   r)   r*   rd      s    
8rd   c                   @  s$   e Zd Z							dddZdS )_ComparesFKsNc              
   C  s   t |d \
}}}}}}}}}}t|d | t|| t|| t|| t||	 t||
 t|| t|| t|| tdd |d jD | |d urv|dkrlt| j|}|d d }t|d j| d S t|d j| d S t|d j| d S )N   r   c                 S  s   g | ]}|j jqS r)   )columnr&   ).0elemr)   r)   r*   
<listcomp>4  s    z0_ComparesFKs._assert_fk_diff.<locals>.<listcomp>servergeneratedr&   )r   r   elementsr   bindget_foreign_keysr&   )selfdiffr-   source_tablesource_columnstarget_tabletarget_columnsr&   conditional_namesource_schemaonupdateondelete	initially
deferrablefk_source_schemafk_source_tablefk_source_columnsfk_target_schemafk_target_tablefk_target_columnsfk_onupdatefk_ondeletefk_deferrablefk_initiallyfksserver_fk_namer)   r)   r*   _assert_fk_diff
  s:   








z_ComparesFKs._assert_fk_diff)NNNNNNN)r^   r_   r`   r   r)   r)   r)   r*   r   	  s    	r   c                   @  sb   e Zd ZU dd Zedd Zi Zded< edd Zed	d
 Z	dd Z
dd Z	dddZdS )AutogenTestc                 c  s2    |D ]}t |tr| |E d H  q|V  qd S r$   )
isinstancelist_flatten_diffs)r   diffsdr)   r)   r*   r   A  s   
zAutogenTest._flatten_diffsc                 C  s   t jS r$   )r   dbrT   r)   r)   r*   	_get_bindH  s   zAutogenTest._get_bindzDict[Any, Any]r   c                 C  s6   t   |  | _|  | _| j| j |  | _d S r$   )r!   r   r   rV   m1
create_allr]   m2r   r)   r)   r*   setup_classN  s
   

zAutogenTest.setup_classc                 C  s   | j | j t  d S r$   )r   drop_allr   r    r   r)   r)   r*   teardown_classV  s   
zAutogenTest.teardown_classc              
   C  sd   | j   | _}dd| jddddttd	}| jr|| j tj	||d | _
}t|| j| _d S )NTupgrades
downgradesop.sa.)	compare_typecompare_server_defaulttarget_metadataupgrade_tokendowngrade_tokenalembic_module_prefixsqlalchemy_module_prefixinclude_objectinclude_name
connectionopts)r   connectconnr   r1   r2   r   updater   	configurecontextr   AutogenContextautogen_context)r   r   ctx_optsr   r)   r)   r*   setUp[  s"   zAutogenTest.setUpc                 C  s   | j   d S r$   )r   closer   r)   r)   r*   tearDownp  s   zAutogenTest.tearDownNc                 C  s>   |d ur
|| j jd< |d ur|g| j _|d ur|g| j _| j S )Ninclude_schemas)r   r   _object_filters_name_filters)r   object_filtersname_filtersr   r)   r)   r*   _update_contexts  s   

zAutogenTest._update_context)NNN)r^   r_   r`   r   rc   r   r   rb   r   r   r   r   r   r)   r)   r)   r*   r   @  s   
 


r   c                   @  s2   e Zd ZddeeddfddZdd Zdd ZdS )	AutogenFixtureTestFNc	                 C  sf  |r| j j}	|	j}
| |	_|	_z||| _}t| jD ]}|| j  q| j  c}dd|dddd|||d
}|r?|	| t
j||d | _}t||}tjg d}t|| |rt|W  d    W |rs| j j}	|
 |	_|	_S S | W  d    W |r| j j}	|
 |	_|	_S S 1 sw   Y  W |r| j j}	|
 |	_|	_d S d S |r| j j}	|
 |	_|	_w )	NTr   r   r   r   )
r   r   r   r   r   r   r   r   r   r   r   r   )r   dialectmax_identifier_length#_user_defined_max_identifier_length_alembic_metadatar   to_listr   r   r   r   r   r   r   r   r   
UpgradeOpsr   _produce_net_changesas_diffs)r   r   r   r   r   r   r   
return_opsr   r   existing_lengthmodel_metadatarU   r   r   r   r   uor)   r)   r*   _fixture  sv   
zAutogenFixtureTest._fixturec                 C  s   t   tj| _d S r$   )r!   r   r   r   r   r)   r)   r*   r     s   zAutogenFixtureTest.setUpc                 C  s2   t | drt| jD ]}|| j qt  d S )Nr   )hasattrr   r   r   r   r   r    )r   rU   r)   r)   r*   r     s   

zAutogenFixtureTest.tearDown)r^   r_   r`   r1   r2   r   r   r   r)   r)   r)   r*   r     s    
8r   )4
__future__r   typingr   r   r   
sqlalchemyr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r    r   r   r   ddl.baser   	migrationr   
operationsr   testingr   r   testing.envr    r!   setr"   rb   listens_forr+   r0   r1   r2   r3   rd   r   r   r   r)   r)   r)   r*   <module>   sR    

bp7?