
    ѮhO                        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j                  ej                        	 	 	 	 	 	 dd       Z ej                  ej"                        dd       Z ej                  ej&                        	 	 	 	 	 	 dd       Z ej                  ej*                        	 	 	 	 	 	 dd       Z ej                  ej.                        dd       Z ej                  ej2                        	 	 	 	 	 	 dd       Z ej                  ej6                        	 	 	 	 	 	 dd       Z ej                  ej:                        	 	 	 	 	 	 d d       Z ej                  ej>                        	 	 	 	 	 	 d!d       Z  ej                  ejB                        d"d       Z" ej                  ejF                        	 	 	 	 	 	 d#d       Z$ ej                  ejJ                        	 	 	 	 	 	 d$d       Z& ej                  ejN                        	 	 	 	 	 	 d%d       Z( ej                  ejR                        	 	 	 	 	 	 d&d       Z*y
)'    )TYPE_CHECKINGschema   )ops)
Operations   )_copy)sqla_2)TableNc                    | j                   j                  j                  | j                   j                  d       |j                  }|j                  }|j
                  }|j                  }|j                  }|j                  }|j                  }|j                  }	|j                  }
|j                  }|j                  }|j                  }fd}|ri|rg| j                  j!                  |t#        j$                  ||      |      }|j&                  D ]&  } ||      s| j                   j)                  |       (  | j                   j*                  ||f||	|
|||||||d
|j,                   |rn| j                  j!                  || j                  j/                  ||      |      }|j&                  D ]&  } ||      s| j                   j1                  |       ( y y )Nc                 ~    t        | t        j                         xr  | j                   xs | j                        S N)
isinstance	sa_schemaPrimaryKeyConstraint_create_rule)
constraintcompilers    k/home/www/academy-backend.kofcorporation.com/venv/lib/python3.12/site-packages/alembic/operations/toimpl.py_count_constraintz'alter_column.<locals>._count_constraint&   s<    j)*H*HII 
'''L:+B+B8+L	
    r   )
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)
operations	operationr   r   r   r   r&   r'   r   r   new_column_namer   r    r!   r   tr   r   s                    @r   r1   r1      s    &&99H ++M!33'??!!E''K%%JF44N++O((H&&G 11

 !!''[-8 ( 

 -- 	<J ,//
;	< !JOO   %# 7+) ,,  !!''!!((e< ( 

 -- 	;J ,..z:	; r   c                     i }|j                   |j                   |d<    | j                  j                  |j                  | j                        fi | y N	if_exists)r;   r"   
drop_tableto_tablemigration_contextr5   r6   r2   s      r   r<   r<   P   sR    	B&#--;JOO:778<>r   c                     |j                  | j                        } | j                  j                  |j                  |f|j
                  |j                  d|j                   y )N)r   r;   )	to_columnr>   r"   drop_columnr'   r   r;   r2   )r5   r6   r3   s      r   rB   rB   Z   sa       !=!=>FJOO %%	
 ,,r   c                     |j                  | j                        }i }|j                  |j                  |d<    | j                  j                  |fi | y Nif_not_exists)to_indexr>   rE   r"   create_index)r5   r6   idxr2   s       r   rG   rG   h   sT     

Z99
:C	B*'55? JOO  ++r   c                     i }|j                   |j                   |d<    | j                  j                  |j                  | j                        fi | y r:   )r;   r"   
drop_indexrF   r>   r?   s      r   rJ   rJ   s   sR    	B&#--;JOO:778
r   c                     i }|j                   |j                   |d<   |j                  | j                        } | j                  j                  |fi | |S rD   )rE   r=   r>   r"   create_table)r5   r6   r2   r-   s       r   rL   rL      sY     
B*'55?z;;<E JOO  -"-Lr   c                 |    | j                   j                  |j                  |j                  |j                         y )Nr   )r"   rename_tabler'   new_table_namer   r5   r6   s     r   rN   rN      s4     OO  i66y?O?O ! r   c                 p    |j                  | j                        }| j                  j                  |       y r   )r=   r>   r"   create_table_commentr5   r6   r-   s      r   rR   rR      s,     z;;<EOO((/r   c                 p    |j                  | j                        }| j                  j                  |       y r   )r=   r>   r"   drop_table_commentrS   s      r   rU   rU      s,     z;;<EOO&&u-r   c                    |j                   }|j                  }|j                  }|j                  }|j                  t        |      }| j                  j	                  |||      } | j                  j                  ||f||j                  d| |j                  D ]8  }t        |t        j                        r| j                  j                  |       : |j                  D ]  }| j                  j!                  |        | j                  j"                  j$                  xr! | j                  j"                  j&                   }	|j(                  }
|
r|	r| j                  j+                  |       y y y )Nr   )r   rE   )r'   r3   r   r2   r-   r
   r,   r"   
add_columnrE   r/   r   r   r   r4   indexesrG   r#   supports_commentsinline_commentsr    create_column_comment)r5   r6   r'   r3   r   r2   r8   r   indexwith_commentr    s              r   rW   rW      sO   %%JFF	B||v##Jv#FAJOO --	
  mm 7
*i&D&DEOO**:67  ,$$U+, 	11 	8''777  nnG<--f5  wr   c                 l    | j                   j                  |j                  | j                               y r   )r"   r4   to_constraintr>   rP   s     r   create_constraintr`      s*     OO""
 < <=r   c                 $   i }|j                    t        st        d      |j                   |d<    | j                  j                  | j
                  j                  |j                  |j                  |j                  |j                        fi | y )NzSQLAlchemy 2.0 requiredr;   r   )r;   r   NotImplementedErrorr"   r0   r,   generic_constraintconstraint_namer'   constraint_typer   r?   s      r   r0   r0      s     
B&%&?@@#--;#JOO##00%%  %%##	 	1 	
 r   c                 |    | j                   j                  |j                  |j                  |j                         y )N)multiinsert)r"   bulk_insertr-   rowsrg   rP   s     r   rh   rh      s0     OOY5J5J   r   c                 z    | j                   j                  j                  |j                  |j                         y )N)execution_options)r>   r"   executesqltextrk   rP   s     r   execute_sqlrn      s4       %%--Y-H-H . r   )r5   r   r6   zops.AlterColumnOpreturnN)r5   r   r6   zops.DropTableOpro   N)r5   r   r6   zops.DropColumnOpro   N)r5   r   r6   zops.CreateIndexOpro   N)r5   r   r6   zops.DropIndexOpro   N)r5   r   r6   zops.CreateTableOpro   r   )r5   r   r6   zops.RenameTableOpro   N)r5   r   r6   zops.CreateTableCommentOpro   N)r5   r   r6   zops.DropTableCommentOpro   N)r5   r   r6   zops.AddColumnOpro   N)r5   r   r6   zops.AddConstraintOpro   N)r5   r   r6   zops.DropConstraintOpro   N)r5   r   r6   zops.BulkInsertOpro   N)r5   r   r6   zops.ExecuteSQLOpro   N)+typingr   
sqlalchemyr   r    r   baser   util.sqla_compatr
   r   sqlalchemy.sql.schemar   implementation_forAlterColumnOpr1   DropTableOpr<   DropColumnOprB   CreateIndexOprG   DropIndexOprJ   CreateTableOprL   RenameTableOprN   CreateTableCommentOprR   DropTableCommentOprU   AddColumnOprW   AddConstraintOpr`   DropConstraintOpr0   BulkInsertOprh   ExecuteSQLOprn    r   r   <module>r      sE   ! *   $ %+ s001;;;;)<;;	;; 2;;| s/ 0 s//0

);
	
 1
 s001,,)<,	, 2, s/ 0 s001)< 2 s001)<	 2 s77800)C0	0 90 s556..)A.	. 7. s/6 06B s223)>	 4 s334)?	 5& s//0);	 1 s//0);	 1r   