o
    8 hO                     @   s  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r,d d	lmZ eej	
					d:ddZeejd;ddZeej	
					d<ddZeej	
					d=ddZeejd>ddZeej	
					d?d d!Zeej	
			"		d@d#d$Zeej	
			%		dAd&d'Zeej	
			(		dBd)d*Z eej!dCd,d-Z"eej#	
			.		dDd/d0Z$eej%	
			1		dEd2d3Z&eej'	
			4		dFd5d6Z(eej)	
			7		dGd8d9Z*dS )H    )TYPE_CHECKINGschema   )ops)
Operations   )_copy)sqla_2)Table
operationsr   	operationops.AlterColumnOpreturnNc                    s   | j j| j jd  |j}|j}|j}|j}|j}|j}|j	}|j
}	|j}
|j}|j}|j} fdd}|rU|rU| jj|t|||d}|jD ]}||rT| j | qH| j j||f||	|
|||||||d
|j |r| jj|| j|||d}|jD ]}||r| j | qd S d S )Nc                    s    t | tj o| j p|  S N)
isinstance	sa_schemaPrimaryKeyConstraint_create_rule)
constraintcompiler a/var/www/html/figdemos/bartoux_crm/venv/lib/python3.10/site-packages/alembic/operations/toimpl.py_count_constraint&   s   z'alter_column.<locals>._count_constraintr   )
nullableserver_defaultnametype_r   existing_typeexisting_server_defaultexisting_nullablecommentexisting_comment)impldialectstatement_compilerr   r!   r    modify_typecolumn_name
table_namer   modify_server_defaultZmodify_namemodify_nullablemodify_commentr#   
schema_objtabler   Columnconstraintsdrop_constraintalter_columnkwcolumnadd_constraint)r   r   r   r!   r    r   r(   r)   r   r   Znew_column_namer   r"   r#   r   tr   r   r   r   r2      sn   


r2   ops.DropTableOpc                 C   8   i }|j d ur|j |d< | jj|| jfi | d S N	if_exists)r:   r$   
drop_tableto_tablemigration_contextr   r   r3   r   r   r   r;   P   s   



r;   ops.DropColumnOpc                 C   s4   | | j}| jj|j|f|j|jd|j d S )N)r   r:   )Z	to_columnr=   r$   drop_columnr)   r   r:   r3   )r   r   r4   r   r   r   r@   Z   s   
r@   ops.CreateIndexOpc                 C   s<   | | j}i }|jd ur|j|d< | jj|fi | d S Nif_not_exists)to_indexr=   rC   r$   create_index)r   r   idxr3   r   r   r   rE   h   s
   

rE   ops.DropIndexOpc                 C   r8   r9   )r:   r$   
drop_indexrD   r=   r>   r   r   r   rH   s   s   



rH   ops.CreateTableOpr   c                 C   s<   i }|j d ur|j |d< || j}| jj|fi | |S rB   )rC   r<   r=   r$   create_table)r   r   r3   r.   r   r   r   rJ      s   

rJ   ops.RenameTableOpc                 C      | j j|j|j|jd d S )Nr   )r$   rename_tabler)   new_table_namer   r   r   r   r   r   rM         
rM   ops.CreateTableCommentOpc                 C      | | j}| j| d S r   )r<   r=   r$   create_table_commentr   r   r.   r   r   r   rS         rS   ops.DropTableCommentOpc                 C   rR   r   )r<   r=   r$   drop_table_commentrT   r   r   r   rW      rU   rW   ops.AddColumnOpc                 C   s   |j }|j}|j}|j}|jd urt|}| jj|||d}| jj||f||j	d| |j
D ]}t|tjs>| j| q0|jD ]}| j| qB| jjjoU| jjj }	|j}
|
re|	rg| j| d S d S d S )Nr   )r   rC   )r)   r4   r   r3   r.   r	   r-   r$   
add_columnrC   r0   r   r   r   r5   indexesrE   r%   supports_commentsinline_commentsr"   create_column_comment)r   r   r)   r4   r   r3   r6   r   indexwith_commentr"   r   r   r   rY      s:   




rY   ops.AddConstraintOpc                 C   s   | j || j d S r   )r$   r5   to_constraintr=   rO   r   r   r   create_constraint   s   
rb   ops.DropConstraintOpc                 C   sT   i }|j d urtstd|j |d< | jj| jj|j|j|j	|j
dfi | d S )NzSQLAlchemy 2.0 requiredr:   r   )r:   r
   NotImplementedErrorr$   r1   r-   Zgeneric_constraintconstraint_namer)   constraint_typer   r>   r   r   r   r1      s   


r1   ops.BulkInsertOpc                 C   rL   )N)multiinsert)r$   bulk_insertr.   rowsrh   rO   r   r   r   ri      rP   ri   ops.ExecuteSQLOpc                 C   s   | j jj|j|jd d S )N)execution_options)r=   r$   executesqltextrl   rO   r   r   r   execute_sql   s   
ro   )r   r   r   r   r   N)r   r   r   r7   r   N)r   r   r   r?   r   N)r   r   r   rA   r   N)r   r   r   rG   r   N)r   r   r   rI   r   r   )r   r   r   rK   r   N)r   r   r   rQ   r   N)r   r   r   rV   r   N)r   r   r   rX   r   N)r   r   r   r`   r   N)r   r   r   rc   r   N)r   r   r   rg   r   N)r   r   r   rk   r   N)+typingr   
sqlalchemyr   r    r   baser   util.sqla_compatr	   r
   sqlalchemy.sql.schemar   Zimplementation_forAlterColumnOpr2   DropTableOpr;   DropColumnOpr@   CreateIndexOprE   DropIndexOprH   CreateTableOprJ   ZRenameTableOprM   CreateTableCommentOprS   DropTableCommentOprW   AddColumnOprY   AddConstraintOprb   DropConstraintOpr1   ZBulkInsertOpri   ZExecuteSQLOpro   r   r   r   r   <module>   s   

>
	








!


