o
    Df                     @   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 R/home/ubuntu/webapp/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      | j || j d S r   )r$   
drop_tableto_tablemigration_contextr   r   r   r   r   r;   P   s   
r;   ops.DropColumnOpc                 C   s0   | | j}| jj|j|fd|ji|j d S )Nr   )	to_columnr=   r$   drop_columnr)   r   r4   )r   r   r5   r   r   r   rA   W   s   
rA   ops.CreateIndexOpc                 C   sH   | | j}i }|jd urtstd|j|d< | jj|fi | d S )NSQLAlchemy 1.4+ requiredif_not_exists)to_indexr=   rD   r
   NotImplementedErrorr$   create_index)r   r   idxr4   r   r   r   rG   a   s   

rG   ops.DropIndexOpc                 C   sD   i }|j d urtstd|j |d< | jj|| jfi | d S )NrC   	if_exists)rJ   r
   rF   r$   
drop_indexrE   r=   )r   r   r4   r   r   r   rK   o   s   



rK   ops.CreateTableOpr   c                 C   s   | | j}| j| |S r   )r<   r=   r$   create_tabler   r   r/   r   r   r   rM   ~   s   rM   ops.RenameTableOpc                 C      | j j|j|j|jd d S Nr   )r$   rename_tabler)   new_table_namer   r>   r   r   r   rR         
rR   ops.CreateTableCommentOpc                 C      | | j}| j| d S r   )r<   r=   r$   create_table_commentrN   r   r   r   rW         rW   ops.DropTableCommentOpc                 C   rV   r   )r<   r=   r$   drop_table_commentrN   r   r   r   rZ      rX   rZ   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   indexesrG   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   r:   r   )r$   r6   to_constraintr=   r>   r   r   r   create_constraint   s   
re   ops.DropConstraintOpc                 C   s(   | j | jj|j|j|j|jd d S rQ   )r$   r2   r.   generic_constraintconstraint_namer)   constraint_typer   r>   r   r   r   r2      s   r2   ops.BulkInsertOpc                 C   rP   )N)multiinsert)r$   bulk_insertr/   rowsrk   r>   r   r   r   rl      rT   rl   ops.ExecuteSQLOpc                 C   s   | j jj|j|jd d S )N)execution_options)r=   r$   executesqltextro   r>   r   r   r   execute_sql   s   
rr   )r   r   r   r   r   N)r   r   r   r9   r   N)r   r   r   r?   r   N)r   r   r   rB   r   N)r   r   r   rI   r   N)r   r   r   rL   r   r   )r   r   r   rO   r   N)r   r   r   rU   r   N)r   r   r   rY   r   N)r   r   r   r[   r   N)r   r   r   rc   r   N)r   r   r   rf   r   N)r   r   r   rj   r   N)r   r   r   rn   r   N)+typingr   
sqlalchemyr   r    r   baser   util.sqla_compatr	   r
   sqlalchemy.sql.schemar   implementation_forAlterColumnOpr3   DropTableOpr;   DropColumnOprA   CreateIndexOprG   DropIndexOprK   CreateTableOprM   RenameTableOprR   CreateTableCommentOprW   DropTableCommentOprZ   AddColumnOpr\   AddConstraintOpre   DropConstraintOpr2   BulkInsertOprl   ExecuteSQLOprr   r   r   r   r   <module>   s   

>

	









