o
    h                     @   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
 er&d dlmZ eej			
				d9d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			
		$		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$			
		0		dDd1d2Z%eej&			
		3		dEd4d5Z'eej(			
		6		dFd7d8Z)dS )G    )TYPE_CHECKINGschema   )ops)
Operations   )_copy)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 m/var/www/html/construction_image-detection-poc/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   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<   O   s   



r<   ops.DropColumnOpc                 C   s0   | | j}| jj|j|fd|ji|j d S )Nr   )	to_columnr>   r#   drop_columnr(   r   r3   )r   r   r4   r   r   r   rB   Y   s   
rB   ops.CreateIndexOpc                 C   s<   | | j}i }|jd ur|j|d< | jj|fi | d S Nif_not_exists)to_indexr>   rE   r#   create_index)r   r   idxr3   r   r   r   rG   c   s
   

rG   ops.DropIndexOpc                 C   r9   r:   )r;   r#   
drop_indexrF   r>   r?   r   r   r   rJ   n   s   



rJ   ops.CreateTableOpr
   c                 C   s<   i }|j d ur|j |d< || j}| jj|fi | |S rD   )rE   r=   r>   r#   create_table)r   r   r3   r.   r   r   r   rL   z   s   

rL   ops.RenameTableOpc                 C      | j j|j|j|jd d S Nr   )r#   rename_tabler(   new_table_namer   r   r   r   r   r   rP         
rP   ops.CreateTableCommentOpc                 C      | | j}| j| d S r   )r=   r>   r#   create_table_commentr   r   r.   r   r   r   rV         rV   ops.DropTableCommentOpc                 C   rU   r   )r=   r>   r#   drop_table_commentrW   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(   r4   r   r3   r.   r	   r-   r#   
add_columnr0   r   r   r   r5   indexesrG   r$   supports_commentsinline_commentsr!   create_column_comment)r   r   r(   r4   r   r3   r7   r   indexwith_commentr!   r   r   r   r\      s*   




r\   ops.AddConstraintOpc                 C   s   | j || j d S r   )r#   r5   to_constraintr>   rR   r   r   r   create_constraint   s   
re   ops.DropConstraintOpc                 C   s(   | j | jj|j|j|j|jd d S rO   )r#   r1   r-   generic_constraintconstraint_namer(   constraint_typer   rR   r   r   r   r1      s   r1   ops.BulkInsertOpc                 C   rN   )N)multiinsert)r#   bulk_insertr.   rowsrk   rR   r   r   r   rl      rS   rl   ops.ExecuteSQLOpc                 C   s   | j jj|j|jd d S )N)execution_options)r>   r#   executesqltextro   rR   r   r   r   execute_sql   s   
rr   )r   r   r   r   r   N)r   r   r   r8   r   N)r   r   r   r@   r   N)r   r   r   rC   r   N)r   r   r   rI   r   N)r   r   r   rK   r   r
   )r   r   r   rM   r   N)r   r   r   rT   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	   sqlalchemy.sql.schemar
   implementation_forAlterColumnOpr2   DropTableOpr<   DropColumnOprB   CreateIndexOprG   DropIndexOprJ   CreateTableOprL   RenameTableOprP   CreateTableCommentOprV   DropTableCommentOprZ   AddColumnOpr\   AddConstraintOpre   DropConstraintOpr1   BulkInsertOprl   ExecuteSQLOprr   r   r   r   r   <module>   s   

>
	
	










