
    h                    ~   d dl mZ d dl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 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 ddlmZ ddlmZ ddlmZ ddlmZ er6d 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! d dlm"Z" d dl#m$Z$ ddl%m&Z&  G d de      Z' eed      	 	 	 	 	 	 d!d        Z(y)"    )annotationsN)Any)Dict)Optional)TYPE_CHECKING)Union)cast)JSON)schema)sql   )alter_table)format_table_name)RenameTable)DefaultImpl   )util)compiles)	Inspector)DDLCompiler)Cast)ClauseElement)Column)
Constraint)Table)
TypeEngine)BatchOperationsImplc                       e Zd ZdZdZ	 	 	 	 	 ddZddZddZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 ddZ		 	 	 	 	 	 	 	 ddZ
	 d	 	 	 	 	 d fd	Z	 	 	 	 	 	 	 	 dd
Zd Z xZS )
SQLiteImplsqliteFc                   |j                   D ]  }|d   dk(  r|d   d   }t        |j                  t        j                        r0t        |j                  j
                  t        j                        r yt        |j                  t        j                  j                        s|j                  j                  s y|d   dvs y y)zReturn True if the given :class:`.BatchOperationsImpl`
        would need the table to be recreated and copied in order to
        proceed.

        Normally, only returns True on SQLite when operations other
        than add_column are present.

        r   
add_columnr   T)create_index
drop_indexF)batch
isinstanceserver_defaultr   DefaultClauseargr   r   r   sqla_compatComputed	persisted)selfbatch_opopcols       ]/var/www/html/retail-simulation-api/retail/lib/python3.12/site-packages/alembic/ddl/sqlite.pyrequires_recreate_in_batchz%SQLiteImpl.requires_recreate_in_batch.   s     ..B!u$eAh&&(<(< !3!3!7!79J9JKs1143C3C3L3LM**44A<< !     c                    |j                   t        d      |j                  |       rt        j                  d       y y )NNo support for ALTER of constraints in SQLite dialect. Please refer to the batch mode feature which allows for SQLite migrations using a copy-and-move strategy.zSkipping unsupported ALTER for creation of implicit constraint. Please refer to the batch mode feature which allows for SQLite migrations using a copy-and-move strategy.)_create_ruleNotImplementedErrorr   warnr-   consts     r1   add_constraintzSQLiteImpl.add_constraintJ   sJ     %%D 
 %IID &r3   c                2    |j                   t        d      y )Nr5   )r6   r7   r9   s     r1   drop_constraintzSQLiteImpl.drop_constraint[   s&    %%D  &r3   c                    |.t        j                  dd|      }t        j                  dd|      }|.t        j                  dd|      }t        j                  dd|      }||k7  S )Nz
^\((.+)\)$z\1z^\"?'(.+)'\"?$)resub)r-   inspector_columnmetadata_columnrendered_metadata_defaultrendered_inspector_defaults        r1   compare_server_defaultz!SQLiteImpl.compare_server_defaultc   s     %0(*u&?)% )+!5*C)% &1)+u&@*& *,!5*D*& *-FFFr3   c                    |syt        j                  d|      ryt        j                  d|      ryt        j                  d|      ryy)a  Determine if a server default is a SQL expression or a constant.

        There are too many assertions that expect server defaults to round-trip
        identically without parenthesis added so we will add parens only in
        very specific cases.

        Fz	^[0-9\.]$z^'.+'$z^\(.+\)$T)r?   match)r-   exprs     r1   -_guess_if_default_is_unparenthesized_sql_exprz8SQLiteImpl._guess_if_default_is_unparenthesized_sql_expr~   s@     XXlD)XXi&XXk4(r3   c                `    | j                  |j                  dd             rd|d   d|d<   y y )Ndefault())rI   get)r-   	inspectortablecolumn_infos       r1   autogen_column_reflectz!SQLiteImpl.autogen_column_reflect   s9     ==OOIt,
 0;9/E%GK	"
r3   c                ^    t        |   |fd|i|}|r| j                  |      rd|d}|S )Nis_server_defaultrL   rM   )superrender_ddl_sql_exprrI   )r-   rH   rT   kwstr_expr	__class__s        r1   rV   zSQLiteImpl.render_ddl_sql_expr   sG    
 7.
$5
9;

 BB8L!)+Hr3   c                    |j                   j                  |j                  ur$t        |t              st	        |d   |      |d<   y y y )NrH   )type_type_affinityr&   r
   r	   )r-   existingexisting_transfernew_types       r1   cast_for_batch_migratez!SQLiteImpl.cast_for_batch_migrate   sK     MM((0G0GGx.(,!&)8)f% / Hr3   c                (    | j                  ||       y )N)_skip_functional_indexes)r-   conn_unique_constraintsconn_indexesmetadata_unique_constraintsmetadata_indexess        r1   correct_for_autogen_constraintsz*SQLiteImpl.correct_for_autogen_constraints   s     	%%&6Er3   )r.   r   returnbool)r:   r   )
rA   Column[Any]rB   rj   rC   Optional[str]rD   rk   rh   ri   )rH   rk   rh   ri   )rO   r   rP   r   rQ   zDict[str, Any]rh   None)F)rH   r   rT   ri   rh   str)r]   rj   r^   z"Dict[str, Union[TypeEngine, Cast]]r_   r   rh   rl   )__name__
__module____qualname____dialect__transactional_ddlr2   r;   r=   rE   rI   rR   rV   r`   rg   __classcell__)rY   s   @r1   r   r   &   s   K+	8"G%G %G $1	G
 %2G 
G6!	*HH H $	H
 
H >C!6:	  > 	
 
Fr3   r   r    c                x    t        || j                  | j                        dt        || j                  d       S )Nz RENAME TO )r   
table_namer   r   new_table_name)elementcompilerrW   s      r1   visit_rename_tablery      s6    
 	Hg00'..A(G$:$:DA r3   )rw   r   rx   r   rh   rm   ))
__future__r   r?   typingr   r   r   r   r   
sqlalchemyr	   r
   r   r   baser   r   r   implr    r   util.sqla_compatr   sqlalchemy.engine.reflectionr   sqlalchemy.sql.compilerr   sqlalchemy.sql.elementsr   r   sqlalchemy.sql.schemar   r   r   sqlalchemy.sql.type_apir   operations.batchr   r   ry    r3   r1   <module>r      s    # 	            #    '63,5,0+26_F _FD 
+x $/ !r3   