mf.UdZddlmZddlmZddlmZmZmZm Z m Z m Z m Z m Z mZmZmZddlZddlmZerddlmZdd lmZmZd Zd ed <d ezZd ed<ddddddddZd ed<dZd ed<dKdZ dLdZ!ej"dej#dej$e ej%e!iZ&ded<Gdd eZdMd%Z' dNd&d'dOd-Z(dPd0Z)dPd1Z*dPd2Z+dQd5Z,dQd6Z-d7d8dRd;Z.dSd?Z/dTd@Z0dQdAZ1dUdDZ2dVdGZ3dWdHZ4dXdJZ5dS)Yz Automatically create migrations.) annotations)Hashable) TYPE_CHECKINGAnyCallableDictFinalIterableListOptionalTypeUnioncastN)Column)Migrator) TModelTypeTParamsz r INDENT NEWLINEpw_pext) ArrayFieldBinaryJSONFieldDateTimeTZField HStoreField IntervalField JSONField TSVectorFieldFIELD_MODULES_MAP)zplayhouse.postgres_extzplayhouse.fieldspeewee PW_MODULESfieldpw.ForeignKeyFieldreturnrc^i}|jd|jd|d<|jd|jd|d<|S)zGet params from the given fk.N' on_delete on_update)r(r)r#paramss J/opt/imunify360/venv/lib64/python3.11/site-packages/peewee_migrate/auto.py fk_to_paramsr-(sJ F "4%/444{ "4%/444{ Mpw.DateTimeFieldcRi}t|jts |j|d<|S)z)Get params from the given datetime field.formats) isinstancer1listr*s r, dtf_to_paramsr44s, F emT * **!My Mr.cd|jiS)N max_length)r6fs r,r9>s \1<8r.c8|j|j|j|jdS)N max_digitsdecimal_places auto_roundroundingr;r7s r,r9r9?s#l*lJ   r.z.Dict[Type[pw.Field], Callable[[Any], TParams]]FIELD_TO_PARAMScJeZdZUdZded<dfd Zddfd Zdfd ZxZS)rz!Get field's migration parameters.Type[pw.Field] field_classr#pw.Fieldc tt||jt ||j|j|j|j|j |j d |j -t|j st|j |_ |jtvr@|ji|_|jt|j|d|_d|_t)|t*jr>|jj|_|j|jkrdnd|jjjz|_dSdS)N) primary_key column_nameindexuniqueextra_parametersz'self'zmigrator.orm['%s'])superr__init__namefind_field_type field_typenullrFrGrHrIdefaultcallablereprrCr@rJupdate rel_modelto_fieldr2pwForeignKeyField rel_fieldmodel_meta table_name)selfr#kwargs __class__s r,rLzColumn.__init__Os: fd$$ J E " "   J))+<! %  = $Xem-D-D $ ..DL   . .$,(*%  ! ( (9I)J5)Q)Q R R R eR/ 0 0 !O0DM?ek11)EO,A,LL NNN  r. spacestrr%ctt|}t|jjd}d|dD\}}}d||||S)z.Generate the field definition for this column.rWc:g|]}|o|S)strip).0ss r, z$Column.get_field..ss$HHHa!/ HHHr.=z%{name}{space}={space}{module}.{field})rMr#ramodule) rKr get_fieldr getrC__name__ partitionformat)r]rar#rkrM_r_s r,rlzColumn.get_fieldosfd##--//"&&t'7'@$GGHH5??33G3GHHHa6==U%>   r.rcxtt|}|j |j|d<|S)z#Generate parameters for self field.NrQ)rKrget_field_parametersrQ)r]r+r_s r,rszColumn.get_field_parametersxs7vt$$99;; < # $ F9  r.)r#rD)r`)rarbr%rb)r%r) rn __module__ __qualname____doc____annotations__rLrlrs __classcell__)r_s@r,rrJs++@       r.rmodel1rmodel2 List[str]c  g}|j|j}}|j|j}tt|z }|r1fd|D}|t |g|Ri|t|tz } | r |t |g| Rg} g} g} t|z | z D]} | || }}t ||}|dd}|dd}|r| ||| | |f|$| | |d|df| r#|t|g| Ri|| D]*\} }|t|| |+| D]\} }}|dus|durc|| j s || j r#|t|| |t|| | q|t|| |j}|j}t|t|z }|D]g}t|dt t"frCt%|ddkr*|t||d ht|t|z }|D]n}t|dt t"frJt%|ddkr1|t||d|d o|S) z,Find difference between given peewee models.c g|] }| Srere)rgrM field_names1s r,rizdiff_one..s888,t$888r.rPNrHrr)rPT)rI)rM)rMrI)r[fieldssetappend create_fields drop_fieldscompare_fieldspop change_fieldschange_not_nullrIrH drop_index add_indexindexesr2r3tuplelen)ryrzr^changesmeta1meta2 field_names2names1rnames2fields_nulls_indexes_rMfield1field2diffrPrHrIindexes1indexes2indexes_to_dropindexes_to_addr~s @r,diff_onersG<5E,D 9z&$77888 NN9VT&AAA B B B B NN:fd33 4 4 4 4}H}H(mmc(mm3O >> eAhu . . >3uQx==13D3D NN:f58<<< = = =]]S]]2NNN eAhu . . N3uQx==13D3D NN9V%(58LLL M M M Nr.F)reversemodels1List[TModelType]models2migratorOptional[Migrator]cttdtj|}ttdtj|}|r8t t |}t t |}d|Dd|Dg}D]5\}}|vr |t|||6fdDD],}| t||-fdDD]*}| t|+|S)z9Calculate changes for migrations from models2 to models1.rcNi|]"}tt|jj|#Srerrbr[r\rgms r, zdiff_many..)EEE4QW/00!EEEr.cNi|]"}tt|jj|#Srerrs r,rzdiff_many..rr.)rcg|]}|v| Srere)rgr models_map2s r,rizdiff_many..#@@@q1K+?+?+?+?+?r.cg|]}|v| Srere)rgr models_map1s r,rizdiff_many..rr.) rr rW sort_modelsr3reverseditemsextendrr create_model remove_model) rrrrrrMryrrs @@r, diff_manyrs4 %r~g'>'>??G4 %r~g'>'>??G*x(())x(())EEWEEEKEEWEEEKG#))++OO f { " " x D(9HMMMNNNNA@@@K@@@KK|K$5IIIJJJJA@@@K@@@88|K$5667777 Nr. model_clsrbc  d}|j}ttfd|jDz}ttt ddtd|jd|jrtd|jdndt|j tj rtd |j j nd|j rtd |j ndgz}||j|| S) z(Generate migrations for the given model.z-class {classname}(pw.Model): {fields} {meta}ctg|]4}t|tjr |jdk't |fi5S)id)r2rWPrimaryKeyFieldrM field_to_codergr#r^s r,riz!model_to_code..sX   ub&899 ?DjD>P>P % * *6 * *>P>P>Pr.Nz class Meta:ztable_name = ""z schema = "zprimary_key = pw.CompositeKeyz indexes = ) classnamermeta)r[rrjoin sorted_fieldsfilterr\schemar2rFrW CompositeKey field_namesrrprn)rr^templaterrs ` r, model_to_coders/AH ?D gll    +   F GLL ;;;;;7;{J633T[3333"$"2BODDv\\D.s/```PU e K K5 KF K K```r.))r[rr\rrrr^rs ` r,rrsf ?DD  =  ````Y_``` a a b b b r.c x|j}d|jddtt|dS)z%Generate migrations to remove fields.zmigrator.remove_fields('rz, r)r[r\rmaprSrs r,rr s= ?DD  #dF##$$$$ r.Traraboolc Nt|fi|}||rdndS)zGenerate field description.r`r)rrl)r#rar^cols r,rr)s2  ! !& ! !C ==-2 . ..r.rrrc Vt|t|}}||krddiSt|}|j|d<t|}|j|d<tt |t |z S)z$Find diffs between the given fields.clsTrP)rNfield_to_paramsrPdictrr)rrr^ftype1ftype2params1params2s r,rr/s$V,,of.E.EFF t}f%%GkGFOf%%GkGFO GMMOO$$s7==??';';; < <.@s"r.NrQrHbackref) rNr@rmrQrRr2rrHrIr)r#r^ftyper+s r,rr=s E " "E   5 5e < .Ss%LLLmAU;;;LLLr.r)r[r\rrrs r,rrNsH ?DD  wLLVLLLMMMM r.rMrPcX|j}|rdnd}d|d|jdt|dS)Generate migrations. drop_not_null add_not_nullz migrator.z('rr)r[r\rS)rrMrPr operations r,rrWs: ?D#';^II&/ii$t**** MMr.Union[str, Iterable[str]]rIcv|j}t|d}d|jd|d|dS)r()[]zmigrator.add_index('rz , unique=rr[rSrfr\)rrMrIrcolumnss r,rr^sE ?D4jjv&&G Q$/ Q Qg Q Q Q Q QQr.cp|j}t|d}d|jd|dS)rrzmigrator.drop_index('rrr)rrMrrs r,rres= ?D4jjv&&G A4? A Aw A A AAr.rBct|}|jtvr)|D]}|jtvr|cS|Sr)typertr"mro)r#rrs r,rNrNlsT KKE z))99;;  C~++ , Lr.)r#r$r%r)r#r/r%r)ryrrzrr%r{r)rrrrrrr%r{)rrr%rb)rrrrDr%rb)r#rDrarr%rb)rrDrrDr%r)r#rDr%r)rrrMrbrPrr%rb)rrrMrrIrr%rb)rrrMrr%rb)r#rDr%rB)6rv __future__rcollections.abcrtypingrrrrr r r r r rrr!rWplayhouse.reflectionr VanilaColumnrrtypesrrrrwrr r"r-r4 CharField DecimalFieldrX DateTimeFieldr@rrrrrrrrrrrrrrrNrer.r,rs&&&""""""$$$$$$                          777777+""""""********  K JJJJ    L88O  m C    33333\333lDDDDT$(!  !!!!!!HSSSS>KKKK ;;;; 59////// = = = ="NNNNRRRRBBBBr.