o
    @j]                     @   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_14)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 h/var/www/www-root/data/www/ai-bot.pdev.uz/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_default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   new_column_namer   r"   r#   r   tr   r   r   r   r3      sn   


r3   ops.DropTableOpc                 C   D   i }|j d urtstd|j |d< | jj|| jfi | d S NSQLAlchemy 1.4+ required	if_exists)r=   r
   NotImplementedErrorr$   
drop_tableto_tablemigration_contextr   r   r4   r   r   r   r?   P   s   



r?   ops.DropColumnOpc                 C   s0   | | j}| jj|j|fd|ji|j d S )Nr   )	to_columnrA   r$   drop_columnr)   r   r4   )r   r   r5   r   r   r   rE   ]   s   
rE   ops.CreateIndexOpc                 C   sH   | | j}i }|jd urtstd|j|d< | jj|fi | d S Nr<   if_not_exists)to_indexrA   rH   r
   r>   r$   create_index)r   r   idxr4   r   r   r   rJ   g   s   

rJ   ops.DropIndexOpc                 C   r:   r;   )r=   r
   r>   r$   
drop_indexrI   rA   rB   r   r   r   rM   u   s   



rM   ops.CreateTableOpr   c                 C   sH   i }|j d urtstd|j |d< || j}| jj|fi | |S rG   )rH   r
   r>   r@   rA   r$   create_table)r   r   r4   r/   r   r   r   rO      s   

rO   ops.RenameTableOpc                 C      | j j|j|j|jd d S Nr   )r$   rename_tabler)   new_table_namer   r   r   r   r   r   rS         
rS   ops.CreateTableCommentOpc                 C      | | j}| j| d S r   )r@   rA   r$   create_table_commentr   r   r/   r   r   r   rY         rY   ops.DropTableCommentOpc                 C   rX   r   )r@   rA   r$   drop_table_commentrZ   r   r   r   r]      r[   r]   ops.AddColumnOpc                 C   s   |j }|j}|j}|j}|jd urt|}| jj|||d}| jj||fd|i| |j	D ]}t
|tjs<| j| q.|jD ]}| j| q@| jjjoS| jjj }	|j}
|
rc|	re| j| d S d S d S )Nr   r   )r)   r5   r   r4   r/   r	   r.   r$   
add_columnr1   r   r   r   r6   indexesrJ   r%   supports_commentsinline_commentsr"   create_column_comment)r   r   r)   r5   r   r4   r8   r   indexwith_commentr"   r   r   r   r_      s*   




r_   ops.AddConstraintOpc                 C   s   | j || j d S r   )r$   r6   to_constraintrA   rU   r   r   r   create_constraint   s   
rh   ops.DropConstraintOpc                 C   s(   | j | jj|j|j|j|jd d S rR   )r$   r2   r.   generic_constraintconstraint_namer)   constraint_typer   rU   r   r   r   r2      s   r2   ops.BulkInsertOpc                 C   rQ   )N)multiinsert)r$   bulk_insertr/   rowsrn   rU   r   r   r   ro      rV   ro   ops.ExecuteSQLOpc                 C   s   | j jj|j|jd d S )N)execution_options)rA   r$   executesqltextrr   rU   r   r   r   execute_sql   s   
ru   )r   r   r   r   r   N)r   r   r   r9   r   N)r   r   r   rC   r   N)r   r   r   rF   r   N)r   r   r   rL   r   N)r   r   r   rN   r   r   )r   r   r   rP   r   N)r   r   r   rW   r   N)r   r   r   r\   r   N)r   r   r   r^   r   N)r   r   r   rf   r   N)r   r   r   ri   r   N)r   r   r   rm   r   N)r   r   r   rq   r   N)+typingr   
sqlalchemyr   r    r   baser   util.sqla_compatr	   r
   sqlalchemy.sql.schemar   implementation_forAlterColumnOpr3   DropTableOpr?   DropColumnOprE   CreateIndexOprJ   DropIndexOprM   CreateTableOprO   RenameTableOprS   CreateTableCommentOprY   DropTableCommentOpr]   AddColumnOpr_   AddConstraintOprh   DropConstraintOpr2   BulkInsertOpro   ExecuteSQLOpru   r   r   r   r   <module>   s   

>

	









