
    g,                       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 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* eed!      d%d#       Z+y)&    )annotationsN)Any)Dict)Optional)TYPE_CHECKING)Union)cast)JSON)schema)sql   )alter_table)
ColumnName)format_column_name)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       Q/var/www/html/AdoubleTech/venv/lib/python3.12/site-packages/alembic/ddl/sqlite.pyrequires_recreate_in_batchz%SQLiteImpl.requires_recreate_in_batch0   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     r3   add_constraintzSQLiteImpl.add_constraintL   sJ     %%D 
 %IID &r5   c                2    |j                   t        d      y )Nr7   )r8   r9   r;   s     r3   drop_constraintzSQLiteImpl.drop_constraint]   s&    %%D  &r5   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        r3   compare_server_defaultz!SQLiteImpl.compare_server_defaulte   s     %0(*u&?)% )+!5*C)% &1)+u&@*& *,!5*D*& *-FFFr5   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)rA   match)r/   exprs     r3   -_guess_if_default_is_unparenthesized_sql_exprz8SQLiteImpl._guess_if_default_is_unparenthesized_sql_expr   s@     XXlD)XXi&XXk4(r5   c                `    | j                  |j                  dd             rd|d   d|d<   y y )Ndefault())rK   get)r/   	inspectortablecolumn_infos       r3   autogen_column_reflectz!SQLiteImpl.autogen_column_reflect   s9     ==OOIt,
 0;9/E%GK	"
r5   c                ^    t        |   |fd|i|}|r| j                  |      rd|d}|S )Nis_server_defaultrN   rO   )superrender_ddl_sql_exprrK   )r/   rJ   rV   kwstr_expr	__class__s        r3   rX   zSQLiteImpl.render_ddl_sql_expr   sG    
 7.
$5
9;

 BB8L!)+Hr5   c                    |j                   j                  |j                  ur$t        |t              st	        |d   |      |d<   y y y )NrJ   )type_type_affinityr(   r
   r	   )r/   existingexisting_transfernew_types       r3   cast_for_batch_migratez!SQLiteImpl.cast_for_batch_migrate   sK     MM((0G0GGx.(,!&)8)f% / Hr5   c                (    | j                  ||       y )N)_skip_functional_indexes)r/   conn_unique_constraintsconn_indexesmetadata_unique_constraintsmetadata_indexess        r3   correct_for_autogen_constraintsz*SQLiteImpl.correct_for_autogen_constraints   s     	%%&6Er5   )r0   r   returnbool)r<   r   )
rC   Column[Any]rD   rl   rE   Optional[str]rF   rm   rj   rk   )rJ   rm   rj   rk   )rQ   r   rR   r   rS   zDict[str, Any]rj   None)F)rJ   r   rV   rk   rj   str)r_   rl   r`   z"Dict[str, Union[TypeEngine, Cast]]ra   r   rj   rn   )__name__
__module____qualname____dialect__transactional_ddlr4   r=   r?   rG   rK   rT   rX   rb   ri   __classcell__)r[   s   @r3   r!   r!   (   s   K+	8"G%G %G $1	G
 %2G 
G6!	*HH H $	H
 
H >C!6:	  > 	
 
Fr5   r!   r"   c                x    t        || j                  | j                        dt        || j                  d       S )Nz RENAME TO )r   
table_namer   r   new_table_nameelementcompilerrY   s      r3   visit_rename_tabler|      s6    
 	Hg00'..A(G$:$:DA r5   c                    t        || j                  | j                        dt        || j                        dt        || j
                        S )Nz RENAME COLUMN z TO )r   rw   r   r   column_namenewnamery   s      r3   visit_column_namer      sB     	Hg00'..A8W%8%898W__5 r5   )rz   r   r{   r   rj   ro   )rz   r   r{   r   rj   ro   ),
__future__r   rA   typingr   r   r   r   r   
sqlalchemyr	   r
   r   r   baser   r   r   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!   r|   r    r5   r3   <module>r      s    # 	             $ #    '63,5,0+26_F _FD 
+x $/ ! 
*h  r5   