|L i+iddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z dd l m Z dd l m Z dd l m Z dd l mZdd l mZddl mZddl mZddl mZddl mZddl mZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&dd lm'Z'dd!lm(Z(dd"lm)Z)er0dd#lm*Z*dd$l+m,Z,dd%l-m.Z.dd&l-m/Z/dd'l0m1Z1dd(lm2Z2dd)l3m4Z4dd*l5m6Z6Gd+d,Z7Gd-d.Z8y/)0) annotations)Any)Dict)List)Optional)Tuple) TYPE_CHECKING)Union)CheckConstraint)Column)ForeignKeyConstraint)Index)MetaData)PrimaryKeyConstraintschema)select)Table)types)SchemaEventTarget) OrderedDict) topological)exc)_columns_for_constraint)_copy)_copy_expression)_ensure_scope_for_ddl)_fk_is_self_referential)_idx_table_bound_expressions)_is_type_bound)_remove_column_from_collection)_resolve_for_variant)constraint_name_defined)constraint_name_string)Literal)Dialect) ColumnClause) quoted_name)Function) Constraint) TypeEngine) DefaultImplceZdZdZeddZeddZddZddZddZ ddZ ddZ dd Z dd Z d Zdd Zdd ZdZdZdZdZdZy)BatchOperationsImplc ||_||_||_|dvr td||_||_||_t||_||_ t| |_ |jjdt|jjdd|jdjd|jj f| |_| |_g|_y)N)autoalwaysneverz4recreate may be one of 'auto', 'always', or 'never'. listenerscolumn_reflect) operations table_namer ValueErrorrecreate copy_from table_argsdict table_kwargs reflect_argsreflect_kwargs setdefaultlistgetappendimplautogen_column_reflectnaming_conventionpartial_reorderingbatch) selfr7r8rr:r;r<r>r?r@rGrHs ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/alembic/operations/batch.py__init__zBatchOperationsImpl.__init__7s%$ 6 6F ! "$ .(">2 && d1155k2FG  K(// zEE F "3"4 cB|jjjSN)r7rEdialectrJs rKrPzBatchOperationsImpl.dialect\s##+++rMc.|jjSrO)r7rErQs rKrEzBatchOperationsImpl.impl`s###rMc|jdk(r%|jjj|S|jdk(ryy)Nr1r2TF)r:r7rErequires_recreate_in_batchrQs rK_should_recreatez$BatchOperationsImpl._should_recreateds; ==F "??''BB4H H ]]h &rMc |j}t|jj5|s?|jD].\}}}t |j j|}||i|0n|jrt|j}n t}|j|j}d}n|j jjrNtjd|j jjjd|j dt#|j |g|j$|j&|j j)d|j*}d}t-|j||j.|j0||j2} |jD]\}}}t | |}||i|| j5|jdddy#1swYyxYw) N)rGFzEThis operation cannot proceed in --sql mode; batch mode with dialect zF requires a live database connection with which to reflect the table "z". To generate a batch SQL migration script using table "move and copy", a complete Table object should be passed to the "copy_from" argument of the batch_alter_table() method so that table reflection can be skipped.)r autoload_withT)rH)rUrrE connectionrIgetattrr7rGrr;migration_contextas_sqlr CommandErrorrPnamer8rr?rget_bindr@ApplyBatchImplr<r>rH_create) rJshould_recreateopnameargkwfnm1existing_table reflected batch_impls rKflushzBatchOperationsImpl.flushls//1 "499#7#7 84 ."'+zz#OFC !5!5v>BNrN#))!D4J4JKB!B>>-%)^^N %I88??!..7#@@HHMMNO559__4EF9 9  &+& ** & ${{&*oo&>&>&@ & -- &N!%I+II"OO%%'+'>'>  (,zz#OFC V4BNrN#""499-i4 .4 .4 .s G HH c@|jjd||fy)N alter_columnrIrDrJrcrds rKrlz BatchOperationsImpl.alter_column >334rMcd|vsd|vr%|jstjd|jj d||fy)N insert_before insert_afterz^Can't specify insert_before or insert_after when using ALTER; please specify recreate='always' add_column)rUrr\rIrDrns rKrszBatchOperationsImpl.add_columnsP r !^r%9'')"":  <b12rMc@|jjd||fy)N drop_columnrmrns rKruzBatchOperationsImpl.drop_columns =#r23rMcB|jjd|fify)Nadd_constraintrmrJconsts rKrwz"BatchOperationsImpl.add_constraints +eXr:;rMcB|jjd|fify)Ndrop_constraintrmrxs rKr{z#BatchOperationsImpl.drop_constraints ,uh;C6267rMc B|jjd|f|fy)N drop_indexrmrs rKrzBatchOperationsImpl.drop_indexs <#45rMcB|jjd|fify)Ncreate_table_commentrmrJtables rKrz(BatchOperationsImpl.create_table_comments 1E8R@ArMcB|jjd|fify)Ndrop_table_commentrmrs rKrz&BatchOperationsImpl.drop_table_comments /%2>?rMctd)Nz Can't create table in batch modeNotImplementedErrorrs rK create_tablez BatchOperationsImpl.create_tables!"DEErMctd)NzCan't drop table in batch moderrs rK drop_tablezBatchOperationsImpl.drop_tables!"BCCrMcB|jjd|fify)Ncreate_column_commentrmrJcolumns rKrz)BatchOperationsImpl.create_column_comments 2VIrBCrMN)returnr')rr-)rboolrNoneryr+rr)rrrdrrr)__name__ __module__ __qualname__rLpropertyrPrErUrjrlrsrurwr{r}rrrrrrrr5rMrKr/r/6s#J,,$$7.r534<=586B@FDDrMr/c<eZdZ d ddZeddZddZddZddZddZ ddZ ddZ d dd Z dd Z d d!d Z d"d ZdZdZdZd#dZd#dZd$dZd$dZdZy )%r_c^||_||_||_||_|j |j |_d|_||_d|_ td|jjD|_ t|j|_||_|j!y)Nr5c3<K|]}|jd|ifywexprN)r]).0cs rK z*ApplyBatchImpl.__init__..s", &'QVVfa[ !, s)rErr<r>_calc_temp_namer]temp_table_name new_tablerHadd_col_orderingrrcolumn_transfersrBexisting_orderingrh_grab_table_elements)rJrErr<r>rhrHs rKrLzApplyBatchImpl.__init__s  $(#33EJJ?*."4  !,, +/::<<, ! "&d&;&;!<" !!#rMcd|zddS)Nz_alembic_tmp_%sr2r5)cls tablenames rKrzApplyBatchImpl._calc_temp_names!I-q44rMc|jj}t|_|jjD]j}t ||}dx|_|_t|jtr|j|jusJ||j|j<li|_ g|_ i|_i|_i|_|jj"D]}t%|r|j&rt|t(r |js8t+|jr||j|j<g|jj-||j&sT|jjD];}|j"D]*}|js||f|j|j<,=|jjD]}||j|j<|jj.D]5}|j0j3||jj.|7y)NrF)rrrcolumnsrruniqueindex isinstancetyperr]named_constraintsunnamed_constraintscol_named_constraintsindexes new_indexes constraintsr!rhr r%rDkwargsr>rA)rJrrc_copyrycolrks rKrz#ApplyBatchImpl._grab_table_elementss""/:}  *A1V,F+0 0FMFL!&&"34{{!&&000#)DLL  *9;#% %'")+ -/ZZ++ 7Ee$uo6 ' 35:&&uzz2((//6 7"~~zz|| N __NEzzBEu225::>N N ::%% )C%(DLL " )"" BA    ( (DJJ,=,=a,@ A BrMcxt}tj}jrDjD]4}t |D]$\}}|dkDs |j ||dz |f&6n.=s"IAAt||A#7"Ic3@K|]}|j|fywrO)rrs rKrzMApplyBatchImpl._adjust_self_columns_for_partial_reordering..>s&, ./Q%%a( ), r) setrBrrH enumerateaddrupdaterrsortrr) rJpairs col_by_idxtuple_relemp pairs_listsorted_s ` rK+_adjust_self_columns_for_partial_reorderingz:ApplyBatchImpl._adjust_self_columns_for_partial_reordering$s6$,,'  " "11 =#,V#4=KE4qy 6%!)#4d";<= = ))?)?@ = t19IIz%!)4d;< =  T**+ "'7A!A$!A$,a7 7   Z N #"I"II +, 3:, !  8s D7D7cx|jJdt}|jj}|js |j r|j t|j|gt|jjt|jzd|i|jx|_}t|jj|jzD]}t!|Dchc]}|j"}}|j%|j&sAt)|t*r2t-|rt/|||j}nt/||}nt/|||}t)|t*r|j1|||j3|ycc}w)NzCan only create new table oncer)r target_tabler)rrrrrHrrrrrBrvaluesr<r>rrrkeyissubsetrrr rr_setup_referentappend_constraint)rJmrrryr const_columns const_copys rK_transfer_elements_to_new_tablez.ApplyBatchImpl._transfer_elements_to_new_tableBs~~%G'GG% J""  " "d&;&;  < < >%*  & 4<<&&()D,AA&  &  &   ''..0 1D4L4L L 4E-DE,JKqQUUKMK ))$*?*?@%!56*51"'f4::"J"'uV!>: #** ~~ %% H JJx ! !$%%,,. E JJJJ8=}}7I7I7KLdnn&&s+L <<ll    %Ms E  Ec |jdj}|jd}|d}t|dk(r|d}nd}||jk7rt j ||}dd}||jvrs|j|} |jD]T} || jdd} | | jvs,| jt| tjVyt||g|jD cgc]} || jddc} D cgc]} t| tjc} d|iyycc} wcc} w) Nr.c"|jSrO) _get_colspec)rs rKcolspecz/ApplyBatchImpl._setup_referent..colspecs((**rMr)rr)elementsrsplitlenr sql_schema_get_table_keytablesr append_columnr sqltypesNULLTYPEr) rJmetadata constraintspecpartstnamereferent_schemarrtrcolnamens rKrzApplyBatchImpl._setup_referentsb""1%224 3b  u:?#AhO"O D(( (++E?CC +hoo%OOC(&//LD%dm11#6r:Gacc)w8I8I(JKL  )3(;(;" $$DM//4R8"q("3"34 +  )$"s !E 1!E" c |j|j||j|jJ|j |j |j |jj jjtd|jjDt|jjDcgc] }d|vr|d c}|j|j|j|j |jj"|jj$|jj"|j_ |j'D]}|j)| |j |j_ycc}w#|j |j_wxYw#|j|jxYw)Nc3.K|] \}}d|vr|ywrr5)rrtransfers rKrz)ApplyBatchImpl._create..s$'Ax!X-srr)rprep_table_for_batchrrr_execinsertinline from_selectrBritemsrrrr}rr]rrr)rJop_implrrs rKr`zApplyBatchImpl._creates ,,.$$T4::6~~)))T^^, ; MM%%'+/+@+@+F+F+H -1,A,A,H,H,J (%1%V,  $   tzz *  $$djjoodjj>O>O ! #'**//DNN  ;@@B.C((-.'+&:&:#+*'+&:&:#    t~~ . s+BG(G-'G(&GG(G%(HNc  |j|} |j|} |||k7r|| _|| d<| jdd} | ret | d|j j } t| tr2| jr&|jj| jd|utj|}t| jtr"dx| j_| j_|j j!| | ||| _ ||| _|dur.|d| _n$t'j(|j+| |t-|| _|dur|| _yy)Nr] existing_typeF)rrr]rCr#rErPrrrpopr to_instancer_create_eventscreate_constraintcast_for_batch_migratenullableserver_defaultr DefaultClause _set_parentr autoincrementcomment)rJr8 column_namerrr]type_rrrdexistingexisting_transferr resolved_existing_types rKrlzApplyBatchImpl.alter_columns<< ,,0,A,A+,N   3!HM(, f %FF?D9M)='):):*& 57HI.33**...33  ((/E(--):; ,MM3 II , ,+U "HM   (H   &%*.'(("+h'  $%)-%8H " % &H  rMcF|j}t|Dcic]\}}|| }}}|jsz|r:|s8||vr||dz}|t|kr||}nt |j |}|r<|s:||vr||dz }|dk\r)||}n#|j D cic]\} } | |  c} } |}|r|xj ||ffz c_|r|xj ||ffz c_|js%|s"|s|r|xj |d|ffz c_yyyyycc}}wcc} } w)Nrrr)rrrHrr=r) rJrrqrr index_colsir] col_indexesrabs rK"_setup_dependencies_for_add_columnz1ApplyBatchImpl._setup_dependencies_for_add_column.sk ++ .7 .CD71dtQwD D&&$#{2),7!;Z0,6sOM)-T-B-B(C() #$ 3)-81<!8+5c?L.2-B-B(%)QAqD('()    ! !w &>%@ @ !   ! !|W&=%? ? !''!   ! !z"~w&?%A A !!"(EE0(s D Dc |j|j||t||jj|j |j<i|j |j<y)Nr)r"r]rrrrr)rJr8rrqrrrds rKrszApplyBatchImpl.add_column^sV // KK  %*&9J9J$K V[[!-/fkk*rMc |j|jjjvr*t |jjj||j|j=|j |j=|j j|jd|vrNt|dtr:|djr*|jj|djdyyyy)Nr ) r]r primary_keyrr"rrremoverrrr )rJr8rrds rKruzApplyBatchImpl.drop_columnns ;;$**0088 8 * &&..  LL %  ! !&++ . %%fkk2 r !2o.0AB?#((  " " & &?#(($ )C "rMcy)a^the batch table creation function will issue create_column_comment on the real "impl" as part of the create table process. That is, the Column object will have the comment on it already, so when it is received by add_column() it will be a normal part of the CREATE TABLE and doesn't need an extra step here. Nr5rs rKrz$ApplyBatchImpl.create_column_commentrMcy)zthe batch table creation function will issue create_table_comment on the real "impl" as part of the create table process. Nr5rs rKrz#ApplyBatchImpl.create_table_commentr(rMcy)zthe batch table creation function will issue drop_table_comment on the real "impl" as part of the create table process. Nr5rs rKrz!ApplyBatchImpl.drop_table_commentr(rMct|js tdt|tj rQ|j j|jvr/|jj|j jt|jr||j|j<y|jj|y)NConstraint must have a name) r$r]r9rrrrr%rr&r%rrDrxs rKrwzApplyBatchImpl.add_constraints&uzz2:; ; eZ<< =zz%%)A)AA((// 0F0FG !%** -16D " "5:: .  $ $ + +E 2rMc\|js td |j|jvr|jj|j\}}t |j |jj D]N}|j|jk(s|j |jj j|Pndt|jr&|jj|j}n)||jvr|jj|t|tr0|j D] }d|j |j_ "yy#t$r&t|rYytd|jzwxYw)Nr,FzNo such constraint: '%s')r]r9rr rBrrr&r%rrrrr%KeyErrorr!)rJryr col_consts rKr{zApplyBatchImpl.drop_constraints]zz:; ; ?zzT777!77;;EJJG U!%dll388&<&H&H!IMI ~~3 SXX.::AA)LM( 3..225::>$222((//6%!56 ==?C9>DLL*6?7 Fe$ 7%**DE E FsBE<"BE<<F+F+c6||j|j<yrO)rr]rJrs rKrzApplyBatchImpl.create_indexs%("rMc~ |j|j=y#t$rtd|jzwxYw)NzNo such index: '%s')rr]r.r9r1s rKrzApplyBatchImpl.drop_indexs; ? SXX& ?2SXX=> > ?s"<ctd)NTODOrrns rKr}zApplyBatchImpl.rename_tables !&))rM)r5)rEr-rrr<tupler>zDict[str, Any]rhrrHr5rr)rzUnion[quoted_name, str]rstrr)rz List[Index])rrrr rr)r r-rr)NFNNNF)r8r6rr6rzOptional[bool]rz)Optional[Union[Function[Any], str, bool]]r] Optional[str]rzOptional[TypeEngine]rz&Optional[Union[bool, Literal['auto']]]rzUnion[str, Literal[False]]rr)rr6rqr7rrr7rr)NN) r8r6rz Column[Any]rqr7rrr7rr)r8r6rz%Union[ColumnClause[Any], Column[Any]]rrr)rrrr)rrrrL classmethodrrrrrrr`rlr"rsrurrrrwr{rrr}r5rMrKr_r_s%'$$$ $ % $  $"$ $:55,B\ <04dB# #.B# #J';Z$(DI"&*@D.3I'I'I'! I' B I'  I'$I'>I',I' I'V.B.B%.B$ .B  .Bh(,&* 000% 0 $ 0 0 6  0   3?8)? *rMr_N)9 __future__rtypingrrrrrr r sqlalchemyr r r rrrrrrrrrsqlalchemy.sql.schemarsqlalchemy.utilrrutilrutil.sqla_compatrrrrrr r!r"r#r$r%r&sqlalchemy.enginer'sqlalchemy.sql.elementsr(r)sqlalchemy.sql.functionsr*r+sqlalchemy.sql.type_apir,ddl.implr-r/r_r5rMrKrEs# &+++(3''6$/46;-=365)43102&[D[D|z*z*rM