%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/alembic/operations/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib/python3.7/site-packages/alembic/operations/__pycache__/batch.cpython-37.pyc

B

�M!Vc+�@s�ddlmZmZmZmZmZmZmZddlmZ	ddlm
Zddlm
Z
ddlmZddlmZmZGdd	�d	e�ZGd
d�de�ZdS)
�)�Table�MetaData�Index�select�Column�ForeignKeyConstraint�cast)�types)�schema)�OrderedDict�)�util)�_columns_for_constraint�_is_type_boundc@s�eZdZdd�Zedd��Zedd��Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS) �BatchOperationsImplcCshtjstd��||_||_||_|dkr0td��||_||_||_	t
|�|_||_|	|_
|
|_g|_dS)Nz.batch mode requires SQLAlchemy 0.8 or greater.)�auto�always�neverz4recreate may be one of 'auto', 'always', or 'never'.)r
Zsqla_08�NotImplementedError�
operations�
table_namer
�
ValueError�recreate�	copy_from�
table_args�dict�table_kwargs�reflect_args�reflect_kwargs�naming_convention�batch)�selfrrr
rrrrrrr�r"�	/batch.py�__init__s"
zBatchOperationsImpl.__init__cCs
|jjjS)N)r�impl�dialect)r!r"r"r#r& szBatchOperationsImpl.dialectcCs|jjS)N)rr%)r!r"r"r#r%$szBatchOperationsImpl.implcCs.|jdkr|jj�|�S|jdkr&dSdSdS)NrrTF)rrr%Zrequires_recreate_in_batch)r!r"r"r#�_should_recreate(s


z$BatchOperationsImpl._should_recreatec	Cs�|��}|s<x�|jD]"\}}}t|jj|�}|||�qWn�|jrPt|jd�}nt�}|jdk	rh|j}n,t|j	|f|j
�|jd|j��d�|j
��}t||j|j�}x(|jD]\}}}t||�}|||�q�W|�|j�dS)N)rT)r
ZautoloadZ
autoload_with)r'r �getattrrr%rrrrrrr
Zget_bindr�ApplyBatchImplrr�_create)	r!Zshould_recreate�opname�arg�kw�fnZm1Zexisting_tableZ
batch_implr"r"r#�flush0s&
"
zBatchOperationsImpl.flushcOs|j�d||f�dS)N�alter_column)r �append)r!r,r-r"r"r#r0Osz BatchOperationsImpl.alter_columncOs|j�d||f�dS)N�
add_column)r r1)r!r,r-r"r"r#r2RszBatchOperationsImpl.add_columncOs|j�d||f�dS)N�drop_column)r r1)r!r,r-r"r"r#r3UszBatchOperationsImpl.drop_columncCs|j�d|fif�dS)N�add_constraint)r r1)r!�constr"r"r#r4Xsz"BatchOperationsImpl.add_constraintcCs|j�d|fif�dS)N�drop_constraint)r r1)r!r5r"r"r#r6[sz#BatchOperationsImpl.drop_constraintcOs|j�d||f�dS)N�rename_table)r r1)r!r,r-r"r"r#r7^sz BatchOperationsImpl.rename_tablecCs|j�d|fif�dS)N�create_index)r r1)r!�idxr"r"r#r8asz BatchOperationsImpl.create_indexcCs|j�d|fif�dS)N�
drop_index)r r1)r!r9r"r"r#r:dszBatchOperationsImpl.drop_indexcCstd��dS)Nz Can't create table in batch mode)r)r!�tabler"r"r#�create_tablegsz BatchOperationsImpl.create_tablecCstd��dS)NzCan't drop table in batch mode)r)r!r;r"r"r#�
drop_tablejszBatchOperationsImpl.drop_tableN)�__name__�
__module__�__qualname__r$�propertyr&r%r'r/r0r2r3r4r6r7r8r:r<r=r"r"r"r#r
src@s~eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zddd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd
S) r)cCs<||_||_||_d|_tdd�|jjD��|_|��dS)Ncss|]}|jd|ifVqdS)�exprN)�name)�.0�cr"r"r#�	<genexpr>usz*ApplyBatchImpl.__init__.<locals>.<genexpr>)r;rr�	new_tablerrE�column_transfers�_grab_table_elements)r!r;rrr"r"r#r$oszApplyBatchImpl.__init__cCs�|jj}t�|_x4|jjD](}|j|d�}d|_|_||j|j<qWi|_	g|_
i|_i|_x:|jj
D].}t|�rvqh|jr�||j	|j<qh|j
�|�qhWx|jjD]}||j|j<q�Wx&|jjD]}|j�||jj|�q�WdS)N)r
F)r;r
r�columnsrE�copy�unique�indexrC�named_constraints�unnamed_constraints�indexes�new_indexesZconstraintsrr1�kwargsr�
setdefault)r!r
rEZc_copyr5r9�kr"r"r#rIys(z#ApplyBatchImpl._grab_table_elementscCs�|jdkstd��t�}|jj}td|ft|j���t|j	��d|i|j
��|_}xnt|j���|jD]V}t
dd�t|�D��}|�|j�s�ql|j||d�}t|t�r�|�||�|�|�qlWdS)NzCan only create new table once�_alembic_batch_tempr
cSsg|]
}|j�qSr")�key)rDrEr"r"r#�
<listcomp>�szBApplyBatchImpl._transfer_elements_to_new_table.<locals>.<listcomp>)r
Ztarget_table)rG�AssertionErrorrr;r
r�listrJ�valuesrrrNrO�setr�issubsetrHrK�
isinstancer�_setup_referentZappend_constraint)r!�mr
rGr5Z
const_columnsZ
const_copyr"r"r#�_transfer_elements_to_new_table�s$
z.ApplyBatchImpl._transfer_elements_to_new_tablecsdg}|��j���xJ�j��D]<}|�t|jf�fdd�|j��D��d|j	i|j
���q W|S)Ncsg|]}�jj|�qSr")rGrE)rD�col)r!r"r#rW�szCApplyBatchImpl._gather_indexes_from_both_tables.<locals>.<listcomp>rL)�extendrPrZrQr1rrCrJ�keysrLrR)r!r9rMr")r!r#� _gather_indexes_from_both_tables�s z/ApplyBatchImpl._gather_indexes_from_both_tablescCs�|jd��}|�d�}|d}t|�dkr6|d}nd}|dkr�t�||�}||jkr�|j|}xl|jD]4}	|	���d�d}
|j�|
�sj|�	t
|
tj��qjWn,t
||fdd�d	d�|jD�D��d
|i�dS)Nr�.����rU���cSsg|]}t|tj��qSr")r�sqltypes�NULLTYPE)rD�nr"r"r#rW�sz2ApplyBatchImpl._setup_referent.<locals>.<listcomp>cSsg|]}|���d�d�qS)rerh)�_get_colspec�split)rD�elemr"r"r#rW�sr
)�elementsrlrm�len�
sql_schemaZ_get_table_keyZtablesrEZcontains_columnZ
append_columnrrirjr)r!ZmetadataZ
constraint�spec�partsZtnameZreferent_schemarV�trnZcolnamer"r"r#r^�s*



zApplyBatchImpl._setup_referentc	Cs�|��|�|j�|�|j�yT|�|jjdd��tdd�|j	�
�D��tdd�|j	��D����|�
|j�Wn|�
|j��YnRX|jd|jj|jjd�|jj|j_z x|��D]}|�|�q�WWdd|j_XdS)	NT)Zinlinecss|]\}}d|kr|VqdS)rBNr")rDrT�transferr"r"r#rF�sz)ApplyBatchImpl._create.<locals>.<genexpr>cSsg|]}d|kr|d�qS)rBr")rDrur"r"r#rW�sz*ApplyBatchImpl._create.<locals>.<listcomp>rU)r
)r`Zprep_table_for_batchr;r<rG�_exec�insertZfrom_selectrYrH�itemsrrZr=r7rCr
rdr8)r!Zop_implr9r"r"r#r*�s0zApplyBatchImpl._createNFcKs�|j|}	|j|}
|dk	r2||kr2||	_||
d<|dk	r\t�|�}||	_t|
d|�|
d<|dk	rj||	_|dk	rx||	_|dk	r�t	|�|	_
dS)NrCrBF)rJrHrCriZto_instance�typer�nullable�server_default�bool�
autoincrement)r!rZcolumn_namerzr{rCZtype_r}r-ZexistingZexisting_transferr"r"r#r0�s


zApplyBatchImpl.alter_columncKs(|j|jjd�|j|j<i|j|j<dS)N)r
)rKr;r
rJrCrH)r!r�columnr-r"r"r#r2szApplyBatchImpl.add_columncKs|j|j=|j|j=dS)N)rJrCrH)r!rr~r-r"r"r#r3s
zApplyBatchImpl.drop_columncCsH|jstd��t|tj�r8|jj|jkr8|j�|jj�||j	|j<dS)NzConstraint must have a name)
rCrr]rqZPrimaryKeyConstraintr;Zprimary_keyrO�removerN)r!r5r"r"r#r4szApplyBatchImpl.add_constraintcCsD|jstd��y|j|j=Wn"tk
r>td|j��YnXdS)NzConstraint must have a namezNo such constraint: '%s')rCrrN�KeyError)r!r5r"r"r#r6#szApplyBatchImpl.drop_constraintcCs||j|j<dS)N)rQrC)r!r9r"r"r#r8+szApplyBatchImpl.create_indexcCs6y|j|j=Wn"tk
r0td|j��YnXdS)NzNo such index: '%s')rPrCr�r)r!r9r"r"r#r:.szApplyBatchImpl.drop_indexcOstd��dS)NZTODO)r)r!r,r-r"r"r#r74szApplyBatchImpl.rename_table)NFNNN)r>r?r@r$rIr`rdr^r*r0r2r3r4r6r8r:r7r"r"r"r#r)ns$

$
	r)N)Z
sqlalchemyrrrrrrrr	rir
rqZsqlalchemy.utilr�r
Zutil.sqla_compatrr�objectrr)r"r"r"r#�<module>s$d

Zerion Mini Shell 1.0