U
    ^g%i,                     @  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 erRd 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*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)
ColumnName)format_column_name)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+   Q/var/www/html/api-medvista/venv/lib/python3.8/site-packages/alembic/ddl/sqlite.pyrequires_recreate_in_batch0   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_constraintL   s    

zSQLiteImpl.add_constraintc                 C  s   |j d krtdd S )Nr/   )r0   r1   r3   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(   r6   r7   r8   r9   r+   r+   r,   compare_server_defaulte   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)r:   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(   rA   rB   rC   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 )NrI   rE   )superrender_ddl_sql_exprr?   )r(   r=   rI   kwZstr_expr	__class__r+   r,   rK      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(   rO   rP   rQ   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-   r4   r5   r<   r?   rG   rK   rS   rT   __classcell__r+   r+   rM   r,   r   (   s    r   r    r   r   rH   )elementcompilerr#   c                 K  s"   dt || j| jt|| jd f S )Nz%s RENAME TO %s)r   
table_namer
   r   Znew_table_namerY   rZ   rL   r+   r+   r,   visit_rename_table   s    r]   r   c                 K  s*   dt || j| jt|| jt|| jf S )Nz%s RENAME COLUMN %s TO %s)r   r[   r
   r   Zcolumn_nameZnewnamer\   r+   r+   r,   visit_column_name   s
    

r^   ),
__future__r   r:   typingr   r   r   r   r   Z
sqlalchemyr   r	   r
   r   baser   r   r   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   r]   r^   r+   r+   r+   r,   <module>   sD    #	