o
    voix7                     @  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% 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+Z0d)e+d,< G d-d. d.Z1G d/d0 d0Z2G d1d2 d2Z3G d3d4 d4e3Z4G d5d6 d6e3Z5d+S )7    )annotations)Any)Dict)Literal)overload)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+   [/home/ubuntu/.local/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   r2   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r8   useridTprimary_keyr(   2   a1pwpw_idxaddressemail_addressd   Fnullableorderorder_idamount      0rF   server_defaultzamount >= 0ck_order_amountr(   extraxuiduser.id)r8   r   r   r
   r   r   r   r   r   r   r	   r   r   clsr8   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 )"Nr9   r:   r;   Tr<   r(   r>   FrE   r?   rR   )rN   rB   rC   rD   streetuq_emailrP   rG   rH   rI   
   rK   rL   rM   user_idrT   zamount > -1rO   itemdescriptionzorder.order_idzlen(description) > 5)r8   r   r   r
   r   r   r   r   r   r   r   r	   rU   r+   r+   r,   _get_model_schemak   sN   

	
zModelOne._get_model_schema)	__name__
__module____qualname____requires__r8   __annotations__classmethodrX   r_   r+   r+   r+   r,   r5   9   s   
 
,r5   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 )NamingConvModelr6   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_qrP   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   )rV   rW   r+   r+   r,   rX      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_conventionrm   rn   Tr<   rq   rr   rs   ru   token_x2check1rP   rw   rx   ry   	token_x3ruserdef_x3_unique_sr{   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   )rV   r   rW   r+   r+   r,   r_      sN   

	
z!NamingConvModel._get_model_schemaN)	r`   ra   rb   rc   configure_optsr   re   rX   r_   r+   r+   r+   r,   rf      s    
8rf   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>6  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`   ra   rb   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   C  s   
zAutogenTest._flatten_diffsc                 C  s   t jS r&   )r    dbrV   r+   r+   r,   	_get_bindJ  s   zAutogenTest._get_bindzDict[Any, Any]r   c                 C  s6   t   |  | _|  | _| j| j |  | _d S r&   )r#   r   r   rX   m1
create_allr_   m2r   r+   r+   r,   setup_classP  s
   

zAutogenTest.setup_classc                 C  s   | j | j t  d S r&   )r   drop_allr   r"   r   r+   r+   r,   teardown_classX  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   r3   r4   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,   tearDownr  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_contextu  s   

zAutogenTest._update_context)NNN)r`   ra   rb   r   re   r   r   rd   r   r   r   r   r   r+   r+   r+   r,   r   B  s   
 


r   c                   @  sr   e Zd Ze				ddddd
dZe				dddddddZddeeddfdddZdd Zdd ZdS )AutogenFixtureTest.)max_identifier_lengthr   r   r   
return_opsLiteral[True]returnops.UpgradeOpsc          	      C     d S r&   r+   	r   r   r   r   r   r   r   r   r   r+   r+   r,   _fixture     zAutogenFixtureTest._fixture)r   r   Literal[False]	list[Any]c          	      C  r   r&   r+   r   r+   r+   r,   r     r   FNboolops.UpgradeOps | list[Any]c	                 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   dialectr   #_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   r   r   r   existing_lengthmodel_metadatarW   r   r   r   r   uor+   r+   r,   r     sv   
c                 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   rW   r+   r+   r,   r     s   

zAutogenFixtureTest.tearDown)....)r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )	r`   ra   rb   r   r   r3   r4   r   r   r+   r+   r+   r,   r     s6    
	8r   )6
__future__r   typingr   r   r   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$   rd   listens_forr-   r2   r3   r4   r5   rf   r   r   r   r+   r+   r+   r,   <module>   sV    

bp7?