o
    ‹åg;  ã                   @  s˜  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 ddlmZ er®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) G d d!„ d!eƒZ*eed"ƒd.d)d*„ƒZ+eed"ƒd/d,d-„ƒZ,dS )0é    )ÚannotationsN)ÚAny)ÚDict)ÚOptional)ÚTYPE_CHECKING)ÚUnion)Úcast)ÚComputed)Ú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                      sz   e Zd ZdZdZ	 d1dd„Zd2dd„Zd2dd„Zd3dd„Zd4dd„Z	d5d!d"„Z
	d6d7‡ fd&d'„Zd8d-d.„Zd/d0„ Z‡  ZS )9Ú
SQLiteImplÚsqliteFÚbatch_opr   ÚreturnÚboolc                 C  sz   |j D ]7}|d dkr1|d d }t|jtjƒr#t|jjtjƒr# dS t|jtƒr0|jj	r0 dS q|d dvr: dS qdS )zÿReturn 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	   Ú	persisted)Úselfr"   ÚopÚcol© r1   úN/var/www/html/flaskapp/venv/lib/python3.10/site-packages/alembic/ddl/sqlite.pyÚrequires_recreate_in_batch1   s&   
ÿþ
ÿþ€ÿz%SQLiteImpl.requires_recreate_in_batchÚconstr   c                 C  s.   |j d u r	tdƒ‚|  | ¡rt d¡ d S d S )Nú No 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.z©Skipping 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.   r4   r1   r1   r2   Úadd_constraintM   s   
ÿ
ÿÿzSQLiteImpl.add_constraintc                 C  s   |j d u r	tdƒ‚d S )Nr5   )r6   r7   r9   r1   r1   r2   Údrop_constraint^   s
   
ÿÿzSQLiteImpl.drop_constraintÚinspector_columnúColumn[Any]Úmetadata_columnÚrendered_metadata_defaultúOptional[str]Úrendered_inspector_defaultc                 C  sP   |d urt  dd|¡}t  dd|¡}|d ur$t  dd|¡}t  dd|¡}||kS )Nz
^\((.+)\)$z\1z^\"?'(.+)'\"?$)ÚreÚsub)r.   r<   r>   r?   rA   r1   r1   r2   Úcompare_server_defaultf   s   ÿÿÿÿz!SQLiteImpl.compare_server_defaultÚexprc                 C  s<   |sdS t  d|¡rdS t  d|¡rdS t  d|¡rdS dS )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)rB   Úmatch)r.   rE   r1   r1   r2   Ú-_guess_if_default_is_unparenthesized_sql_expr�   s   
z8SQLiteImpl._guess_if_default_is_unparenthesized_sql_exprÚ	inspectorr   Útabler   Úcolumn_infoúDict[str, Any]ÚNonec                 C  s,   |   | dd ¡¡rd|d f |d< d S d S )NÚdefaultú(%s))rG   Úget)r.   rH   rI   rJ   r1   r1   r2   Úautogen_column_reflect–   s
   
ÿýz!SQLiteImpl.autogen_column_reflectr   Úis_server_defaultÚstrc                   s4   t ƒ j|fd|i|¤Ž}|r|  |¡rd|f }|S )NrQ   rN   )ÚsuperÚrender_ddl_sql_exprrG   )r.   rE   rQ   ÚkwÚstr_expr©Ú	__class__r1   r2   rT   £   s   ÿÿÿÿþ
zSQLiteImpl.render_ddl_sql_exprÚexistingÚexisting_transferú"Dict[str, Union[TypeEngine, Cast]]Únew_typer   c                 C  s6   |j j|jurt|tƒst|d |ƒ|d< d S d S d S )NrE   )ÚtypeÚ_type_affinityr)   r
   r   )r.   rY   rZ   r\   r1   r1   r2   Úcast_for_batch_migrate³   s   ÿÿýz!SQLiteImpl.cast_for_batch_migratec                 C  s   |   ||¡ d S )N)Ú_skip_functional_indexes)r.   Úconn_unique_constraintsÚconn_indexesÚmetadata_unique_constraintsÚmetadata_indexesr1   r1   r2   Úcorrect_for_autogen_constraintsÁ   s   z*SQLiteImpl.correct_for_autogen_constraints)r"   r   r#   r$   )r4   r   )
r<   r=   r>   r=   r?   r@   rA   r@   r#   r$   )rE   r@   r#   r$   )rH   r   rI   r   rJ   rK   r#   rL   )F)rE   r   rQ   r$   r#   rR   )rY   r=   rZ   r[   r\   r   r#   rL   )Ú__name__Ú
__module__Ú__qualname__Ú__dialect__Útransactional_ddlr3   r:   r;   rD   rG   rP   rT   r_   re   Ú__classcell__r1   r1   rW   r2   r    )   s    





ÿ
r    r!   Úelementr   Úcompilerr   r#   rR   c                 K  s"   dt || j| jƒt|| jd ƒf S )Nz%s RENAME TO %s)r   Ú
table_namer   r   Únew_table_name©rl   rm   rU   r1   r1   r2   Úvisit_rename_tableË   s   þrq   r   c                 K  s*   dt || j| jƒt|| jƒt|| jƒf S )Nz%s RENAME COLUMN %s TO %s)r   rn   r   r   Úcolumn_nameÚnewnamerp   r1   r1   r2   Úvisit_column_nameÕ   s
   

ýrt   )rl   r   rm   r   r#   rR   )rl   r   rm   r   r#   rR   )-Ú
__future__r   rB   Útypingr   r   r   r   r   Ú
sqlalchemyr   r	   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    rq   rt   r1   r1   r1   r2   Ú<module>   sH    #	