o
    h;                     @  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rd 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 )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	   	persisted)selfr"   opcol r1   f/var/www/html/construction_image-detection-poc/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 )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.   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    #	