U
    #i                     @  sj  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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"d#d$d%Z(dS )&    )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                      s   e Zd ZdZdZdddddZdd	d
dZdd	ddZddddddddZdddddZ	dddddddZ
d)dddd fd d!Zdd"d#dd$d%d&Zd'd( Z  ZS )*
SQLiteImplsqliteFr   bool)batch_opreturnc                 C  s~   |j D ]r}|d dkrf|d d }t|jtjrFt|jjtjrF dS t|jtj	j
rx|jjrx dS q|d dkr dS qdS )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)Zcreate_indexZ
drop_indexFN)batch
isinstanceZserver_defaultr
   ZDefaultClauseargr   r   r   Zsqla_compatZComputedZ	persisted)selfr    opcol r)   Z/var/www/html/me.goteku.com/backend/venv/lib/python3.8/site-packages/alembic/ddl/sqlite.pyrequires_recreate_in_batch.   s$    
 z%SQLiteImpl.requires_recreate_in_batchr   )constc                 C  s,   |j d krtdn| | r(td d S )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&   r,   r)   r)   r*   add_constraintJ   s    

zSQLiteImpl.add_constraintc                 C  s   |j d krtdd S )Nr-   )r.   r/   r1   r)   r)   r*   drop_constraint[   s    
zSQLiteImpl.drop_constraintzColumn[Any]zOptional[str])inspector_columnmetadata_columnrendered_metadata_defaultrendered_inspector_defaultr!   c                 C  sP   |d k	r$t dd|}t dd|}|d k	rHt dd|}t dd|}||kS )Nz
^\((.+)\)$z\1z^\"?'(.+)'\"?$)resub)r&   r4   r5   r6   r7   r)   r)   r*   compare_server_defaultc   s.            z!SQLiteImpl.compare_server_default)exprr!   c                 C  s@   |sdS t d|rdS t d|r(dS t d|r8dS 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^\(.+\)$TN)r8   match)r&   r;   r)   r)   r*   -_guess_if_default_is_unparenthesized_sql_expr~   s    
z8SQLiteImpl._guess_if_default_is_unparenthesized_sql_exprr   r   zDict[str, Any]None)	inspectortablecolumn_infor!   c                 C  s(   |  |dd r$d|d f |d< d S )Ndefault(%s))r=   get)r&   r?   r@   rA   r)   r)   r*   autogen_column_reflect   s    
z!SQLiteImpl.autogen_column_reflectr   str)r;   is_server_defaultr!   c                   s4   t  j|fd|i|}|r0| |r0d|f }|S )NrG   rC   )superrender_ddl_sql_exprr=   )r&   r;   rG   kwZstr_expr	__class__r)   r*   rI      s    
zSQLiteImpl.render_ddl_sql_exprz"Dict[str, Union[TypeEngine, Cast]]r   )existingexisting_transfernew_typer!   c                 C  s.   |j j|jk	r*t|ts*t|d ||d< d S )Nr;   )typeZ_type_affinityr$   r	   r   )r&   rM   rN   rO   r)   r)   r*   cast_for_batch_migrate   s     z!SQLiteImpl.cast_for_batch_migratec                 C  s   |  || d S )N)Z_skip_functional_indexes)r&   Zconn_unique_constraintsZconn_indexesZmetadata_unique_constraintsZmetadata_indexesr)   r)   r*   correct_for_autogen_constraints   s    z*SQLiteImpl.correct_for_autogen_constraints)F)__name__
__module____qualname__Z__dialect__Ztransactional_ddlr+   r2   r3   r:   r=   rE   rI   rQ   rR   __classcell__r)   r)   rK   r*   r   &   s    r   r   r   r   rF   )elementcompilerr!   c                 K  s"   dt || j| jt|| jd f S )Nz%s RENAME TO %s)r   Z
table_namer
   r   Znew_table_name)rW   rX   rJ   r)   r)   r*   visit_rename_table   s    rY   ))
__future__r   r8   typingr   r   r   r   r   Z
sqlalchemyr   r	   r
   r   baser   r   r   implr    r   Zutil.sqla_compatr   Zsqlalchemy.engine.reflectionr   Zsqlalchemy.sql.compilerr   Zsqlalchemy.sql.elementsr   r   Zsqlalchemy.sql.schemar   r   r   Zsqlalchemy.sql.type_apir   Zoperations.batchr   r   rY   r)   r)   r)   r*   <module>   s<    #