
    h                        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_14)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    d/var/www/html/retail-simulation-api/retail/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                 l    | j                   j                  |j                  | j                               y r   )r"   
drop_tableto_tablemigration_contextr5   r6   s     r   r:   r:   P   s(    OO:778r   c                     |j                  | j                        } | j                  j                  |j                  |fd|j
                  i|j                   y )Nr   )	to_columnr<   r"   drop_columnr'   r   r2   )r5   r6   r3   s      r   r@   r@   W   sS       !=!=>FJOOf-6-=-=AJr   c                     |j                  | j                        }i }|j                   t        st	        d      |j                  |d<    | j
                  j                  |fi | y )NSQLAlchemy 1.4+ requiredif_not_exists)to_indexr<   rC   r   NotImplementedErrorr"   create_index)r5   r6   idxr2   s       r   rF   rF   a   sc     

Z99
:C	B*%&@AA'55? JOO  ++r   c                     i }|j                    t        st        d      |j                   |d<    | j                  j                  |j                  | j                        fi | y )NrB   	if_exists)rI   r   rE   r"   
drop_indexrD   r<   )r5   r6   r2   s      r   rJ   rJ   o   sa    	B&%&@AA#--;JOO:778
r   c                 r    |j                  | j                        }| j                  j                  |       |S r   )r;   r<   r"   create_tabler5   r6   r-   s      r   rL   rL   ~   s1     z;;<EOO  'Lr   c                 |    | j                   j                  |j                  |j                  |j                         y Nr   )r"   rename_tabler'   new_table_namer   r=   s     r   rP   rP      s4     OO  i66y?O?O ! r   c                 p    |j                  | j                        }| j                  j                  |       y r   )r;   r<   r"   create_table_commentrM   s      r   rS   rS      s,     z;;<EOO((/r   c                 p    |j                  | j                        }| j                  j                  |       y r   )r;   r<   r"   drop_table_commentrM   s      r   rU   rU      s,     z;;<EOO&&u-r   c                    |j                   }|j                  }|j                  }|j                  }|j                  t        |      }| j                  j	                  |||      } | j                  j                  ||fd|i| |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   )r'   r3   r   r2   r-   r
   r,   r"   
add_columnr/   r   r   r   r4   indexesrF   r#   supports_commentsinline_commentsr    create_column_comment)r5   r6   r'   r3   r   r2   r8   r   indexwith_commentr    s              r   rW   rW      s,   %%JFF	B||v##Jv#FAJOOz6G&GBGmm
*i&D&DEOO**:6 $ $$U+  	11 	8''777  nnG<--f5  wr   c                 l    | j                   j                  |j                  | j                               y r   )r"   r4   to_constraintr<   r=   s     r   create_constraintr`      s*     OO""
 < <=r   c                     | j                   j                  | j                  j                  |j                  |j
                  |j                  |j                               y rO   )r"   r0   r,   generic_constraintconstraint_namer'   constraint_typer   r=   s     r   r0   r0      sS     OO##00%%  %%##	 	1 	
r   c                 |    | j                   j                  |j                  |j                  |j                         y )N)multiinsert)r"   bulk_insertr-   rowsrf   r=   s     r   rg   rg      s0     OOY5J5J   r   c                 z    | j                   j                  j                  |j                  |j                         y )N)execution_options)r<   r"   executesqltextrj   r=   s     r   execute_sqlrm      s4       %%--Y-H-H . r   )r5   r   r6   zops.AlterColumnOpreturnN)r5   r   r6   zops.DropTableOprn   N)r5   r   r6   zops.DropColumnOprn   N)r5   r   r6   zops.CreateIndexOprn   N)r5   r   r6   zops.DropIndexOprn   N)r5   r   r6   zops.CreateTableOprn   r   )r5   r   r6   zops.RenameTableOprn   N)r5   r   r6   zops.CreateTableCommentOprn   N)r5   r   r6   zops.DropTableCommentOprn   N)r5   r   r6   zops.AddColumnOprn   N)r5   r   r6   zops.AddConstraintOprn   N)r5   r   r6   zops.DropConstraintOprn   N)r5   r   r6   zops.BulkInsertOprn   N)r5   r   r6   zops.ExecuteSQLOprn   N)+typingr   
sqlalchemyr   r    r   baser   util.sqla_compatr
   r   sqlalchemy.sql.schemar   implementation_forAlterColumnOpr1   DropTableOpr:   DropColumnOpr@   CreateIndexOprF   DropIndexOprJ   CreateTableOprL   RenameTableOprP   CreateTableCommentOprS   DropTableCommentOprU   AddColumnOprW   AddConstraintOpr`   DropConstraintOpr0   BulkInsertOprg   ExecuteSQLOprm    r   r   <module>r      sD   ! *   $ &+ 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66 s223)>	 4 s334

)?
	
 5
 s//0);	 1 s//0);	 1r   