ó
    ¼RjëI  ã                   ód   • S SK Jr  S SKJrJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr   " S S	5      rg
)é    )Úapps)Ú
migrationsÚrouteré   )ÚInvalidMigrationPlan)ÚMigrationLoader)ÚMigrationRecorder)ÚProjectStatec                   ór   • \ rS rSrSrSS jrSS jrSS jrSS jrS r	S	 r
SS
 jrS rSS jrS rS rSrg)ÚMigrationExecutoré
   zi
End-to-end migration execution - load migrations and run them up or down
to a specified set of targets.
Nc                 ó„   • Xl         [        U R                   5      U l        [        U R                   5      U l        X l        g ©N)Ú
connectionr   Úloaderr	   ÚrecorderÚprogress_callback)Úselfr   r   s      ÚID:\diplom_project\venv\Lib\site-packages\django/db/migrations/executor.pyÚ__init__ÚMigrationExecutor.__init__   s-   € Ø$ŒÜ% d§o¡oÓ6ˆŒÜ)¨$¯/©/Ó:ˆŒØ!2Õó    c                 óŠ  ^	• / nU(       a  0 nO[        U R                  R                  5      nU GH�  m	T	S   c³  U R                  R                  R	                  5        H‰  nUS   T	S   :X  d  M  U R                  R                  R                  U5       HO  nXd;   d  M
  UR                  U R                  R                  R                  U   S45        UR                  U5        MQ     M‹     M½  T	U;   Ga?  U R                  R                  (       a`  T	U R                  R                  R                  ;  a<  SU R                  l	        U R                  R                  5         U R                  XS9s  $ [        U	4S jU R                  R                  R                  T	   R                   5       5      nU H{  nU R                  R                  R                  U5       HO  nXd;   d  M
  UR                  U R                  R                  R                  U   S45        UR                  U5        MQ     M}     GM  U R                  R                  R                  T	5       Hc  nXd;  d  M
  UR                  U R                  R                  R                  U   S45        U R                  R                  R                  U   XF'   Me     GM’     U$ )zL
Given a set of targets, return a list of (Migration instance, backwards?).
r   r   TF©Úclean_startc              3   óD   >#   • U  H  nUS    TS    :X  d  M  Uv •  M     g7f)r   N© )Ú.0ÚnÚtargets     €r   Ú	<genexpr>Ú3MigrationExecutor.migration_plan.<locals>.<genexpr>8   s*   øé € ð %âH˜Ø˜‘t˜v a™yÑ(÷ ‘AÚHùs   ƒ —	 )Údictr   Úapplied_migrationsÚgraphÚ
root_nodesÚbackwards_planÚappendÚnodesÚpopÚreplace_migrationsÚnode_mapÚbuild_graphÚmigration_planÚsortedÚchildrenÚforwards_plan)
r   Útargetsr   ÚplanÚappliedÚrootÚ	migrationÚnext_in_appÚnoder    s
            @r   r.   Ú MigrationExecutor.migration_plan   s-  ø€ ð ˆÞØ‰Gä˜4Ÿ;™;×9Ñ9Ó:ˆGÜˆFà�a‰yÑ Ø ŸK™K×-Ñ-×8Ñ8Ö:�DØ˜A‘w &¨¡)Õ+Ø)-¯©×):Ñ):×)IÑ)IÈ$Ö)O˜IØ(Õ3Ø $§¡¨T¯[©[×->Ñ->×-DÑ-DÀYÑ-OÐQUÐ,VÔ WØ '§¡¨IÖ 6ó *Pó ;ð ˜7Ô"ð —K‘K×2×2Ø d§k¡k×&7Ñ&7×&@Ñ&@Ó@à5:�D—K‘KÔ2Ø—K‘K×+Ñ+Ô-Ø×.Ñ.¨wÐ.ÐPÒPô
 %ô %à!Ÿ[™[×.Ñ.×7Ñ7¸Ñ?×HÒHó%ó �ó
 (�DØ%)§[¡[×%6Ñ%6×%EÑ%EÀdÖ%K˜	Ø$Õ/Ø ŸK™K¨¯©×):Ñ):×)@Ñ)@ÀÑ)KÈTÐ(RÔSØ#ŸK™K¨	Ö2ó &Lô (ð "&§¡×!2Ñ!2×!@Ñ!@ÀÖ!H�IØ Õ/ØŸ™ T§[¡[×%6Ñ%6×%<Ñ%<¸YÑ%GÈÐ$OÔPØ-1¯[©[×->Ñ->×-DÑ-DÀYÑ-O˜Ó*ô "IñI ðP ˆr   c                 óØ  • [        U R                  R                  S9nU(       aÀ  U R                  U R                  R                  R                  5       SS9nU R                  R                   Vs1 s HK  nX@R                  R                  R                  ;   d  M(  U R                  R                  R                  U   iMM     nnU H  u  pgXe;   d  M  UR                  USS9  M     U$ s  snf )z‚
Create a project state including all the applications without
migrations and applied migrations if with_applied_migrations=True.
)Ú	real_appsTr   F©Úpreserve)	r
   r   Úunmigrated_appsr.   r%   Ú
leaf_nodesr$   r)   Úmutate_state)r   Úwith_applied_migrationsÚstateÚ	full_planÚkeyr$   r6   Ú_s           r   Ú_create_project_stateÚ'MigrationExecutor._create_project_stateI   sÔ   € ô
  t§{¡{×'BÑ'BÑCˆÞ"à×+Ñ+Ø—‘×!Ñ!×,Ñ,Ó.¸Dð ,ð ˆIð
  Ÿ;™;×9Ò9ó"â9�CØŸ+™+×+Ñ+×1Ñ1Ñ1ó -�—‘×!Ñ!×'Ñ'¨Ô,Ù9ð ð "ó
 !*‘�	ØÕ2Ø×*Ñ*¨5¸5Ð*ÓAñ !*ð ˆùò"s   Á/'C'Â'C'c                 ód  • U/ :X  a/  U R                   R                  5       (       d  U R                  SS9$ OU R                   R                  5         Uc  U R	                  U5      nU R	                  U R
                  R                  R                  5       SS9n[        S U 5       5      n[        S U 5       5      nU(       d  Uc  U R                  SS9nOLXx:X  a  [        SU5      eU(       a$  Uc  U R                  SS9nU R                  X2XdUS9nOU R                  X&US	9nU R                  5         U$ )
z¸
Migrate the database up to the given targets.

Django first needs to create all project states before a migration is
(un)applied and in a second step run all the database operations.
F)rA   Tr   c              3   ó4   #   • U  H  u  pU(       + v •  M     g 7fr   r   ©r   ÚmigÚ	backwardss      r   r!   Ú,MigrationExecutor.migrate.<locals>.<genexpr>t   s   é € ÐDºt©^¨S˜yŸ=™=ºtùs   ‚c              3   ó*   #   • U  H	  u  pUv •  M     g 7fr   r   rJ   s      r   r!   rM   u   s   é € ÐAºD©.¨#�IºDùs   ‚z°Migration plans with both forwards and backwards migrations are not supported. Please split your migration process into separate plans of only forwards OR backwards migrations.©ÚfakeÚfake_initial©rP   )r   Ú	has_tablerF   Úensure_schemar.   r   r%   r?   Úallr   Ú_migrate_all_forwardsÚ_migrate_all_backwardsÚcheck_replacements)	r   r2   r3   rB   rP   rQ   rC   Úall_forwardsÚall_backwardss	            r   ÚmigrateÚMigrationExecutor.migrate^   sH  € ð �2‹:Ø—=‘=×*Ñ*×,Ñ,Ø×1Ñ1È%Ð1ÐPÐPð -ð �M‰M×'Ñ'Ô)à‰<Ø×&Ñ& wÓ/ˆDà×'Ñ'Ø�K‰K×Ñ×(Ñ(Ó*¸ð (ð 
ˆ	ô ÑD¹tÓDÓDˆÜÑA¹DÓAÓAˆæØ‰}à×2Ñ2È4Ð2ÐP�øØÓ*ä&ðKð ó	ð ö Ø‰}à×2Ñ2È4Ð2ÐP�Ø×.Ñ.Ø˜YÀð /ð ‰Eð ×/Ñ/°ÀdÐ/ÐKˆEà×ÑÔ!àˆr   c                 ór  • U Vs1 s H  ofS   iM	     nnU H—  u  p‰U(       d    U$ X‡;   d  M  SUR                   ;  aP  U R                  (       a  U R                  S5        UR                    U R                  (       a  U R                  S5        U R                  XXES9nUR	                  U5        M™     U$ s  snf )zz
Take a list of 2-tuples of the form (migration instance, False) and
apply them in the order they occur in the full_plan.
r   r   Úrender_startÚrender_successrO   )Ú__dict__r   r   Úapply_migrationÚremove)
r   rB   r3   rC   rP   rQ   ÚmÚmigrations_to_runr6   rE   s
             r   rV   Ú'MigrationExecutor._migrate_all_forwards“   s¶   € ñ
 ,0Ó0ª4 a˜qœT©4ÐÐ0Û%‰LˆIÞ$ð
 ð ˆð Õ-Ø §¡Ó/Ø×-×-Ø×.Ñ.¨~Ô>Ø—J’JØ×-×-Ø×.Ñ.Ð/?Ô@Ø×,Ñ,Ø¨4ð -ð �ð "×(Ñ(¨Ö3ñ# &ð& ˆùò) 1s   …B4c                 ó¦  • U Vs1 s H  oDS   iM	     nn0 nU R                  5       nU R                  R                   Vs1 s HK  nX€R                  R                  R                  ;   d  M(  U R                  R                  R                  U   iMM     n	nU R
                  (       a  U R                  S5        U Hm  u  p«U(       d    OcX¥;   aC  SUR                  ;  a  UR                    XvU
'   U
R                  USS9nUR                  U
5        MV  X©;   d  M]  U
R                  USS9  Mo     U R
                  (       a  U R                  S5        U H(  u  p«U R                  Xj   X£S9  U	R                  U
5        M*     US	   S   nXl   n[        U5       H4  u  nu  p«X¬:X  d  M  X-S
  H  u  p«X©;   d  M  U
R                  USS9  M       U$    U$ s  snf s  snf )a`  
Take a list of 2-tuples of the form (migration instance, True) and
unapply them in reverse order they occur in the full_plan.

Since unapplying a migration requires the project state prior to that
migration, Django will compute the migration states before each of them
in a first run over the plan and then unapply them in a second run over
the plan.
r   r^   r   Tr<   Fr_   rR   éÿÿÿÿN)rF   r   r$   r%   r)   r   r`   r   r@   rb   Úunapply_migrationÚ	enumerate)r   r3   rC   rP   rc   rd   ÚstatesrB   rD   r$   r6   rE   Úlast_unapplied_migrationÚindexs                 r   rW   Ú(MigrationExecutor._migrate_all_backwards®   s×  € ñ ,0Ó0ª4 a˜qœT©4ÐÐ0àˆØ×*Ñ*Ó,ˆð —{‘{×5Ò5ó
â5�Ø—k‘k×'Ñ'×-Ñ-Ñ-ó )ˆD�K‰K×Ñ×#Ñ# CÔ(Ù5ð 	ð 
ð
 ×!×!Ø×"Ñ" >Ô2Û%‰LˆIÞ$ñ
 ØÓ-Ø §¡Ó/Ø—J’Jà$)�yÑ!à!×.Ñ.¨u¸tÐ.ÐD�Ø!×(Ñ(¨Ö3ØÕ0ð ×&Ñ& u°uÐ&Ó=ñ' &ð( ×!×!Ø×"Ñ"Ð#3Ô4ã ‰LˆIØ×"Ñ" 6Ñ#4°iÐ"ÑKØ×%Ñ% iÖ0ñ !ð $(¨¡8¨A¡;Ð ØÑ0ˆÜ%.¨yÖ%9Ñ!ˆE‘>�IØÕ4Ø$-¨fÓ$5‘L�IØ Õ6Ø!×.Ñ.¨u¸uÐ.ÓEñ %6ð àˆñ &:ð ˆùòe 1ùò
s   …G	¿'GÁ*'Gc                 ó  • SnU R                   (       a  U R                  SX#5        U(       d‹  U(       a  U R                  X5      u  paU(       a  SnU(       da  U R                  R                  UR                  S9 nUR                  X5      nUR                  (       d  U R                  U5        SnSSS5        U(       d  U R                  U5        U R                   (       a  U R                  SX#5        U$ ! , (       d  f       NK= f)zRun a migration forwards.FÚapply_startT©ÚatomicNÚapply_success)r   Údetect_soft_appliedr   Úschema_editorrq   ÚapplyÚdeferred_sqlÚrecord_migration)r   rB   r6   rP   rQ   Úmigration_recordedr4   rt   s           r   ra   Ú!MigrationExecutor.apply_migrationì   sÓ   € à"ÐØ×!×!Ø×"Ñ" =°)ÔBÞÞà!%×!9Ñ!9¸%Ó!K‘�ÞØ�DÞà—_‘_×2Ñ2Ø$×+Ñ+ð 3ñ à"Ø%ŸO™O¨EÓA�EØ(×5×5Ø×-Ñ-¨iÔ8Ø-1Ð*÷ö "Ø×!Ñ! )Ô,à×!×!Ø×"Ñ" ?°IÔDØˆ÷õ ús   Á:6C5Ã5
Dc                 óè   • UR                   (       a1  UR                    H   u  p#U R                  R                  X#5        M"     g U R                  R                  UR                  UR                  5        g r   )Úreplacesr   Úrecord_appliedÚ	app_labelÚname)r   r6   r}   r~   s       r   rw   Ú"MigrationExecutor.record_migration  sO   € à××Ø#,×#5Ô#5‘�	Ø—‘×,Ñ,¨YÖ=ò $6ð �M‰M×(Ñ(¨×)<Ñ)<¸i¿n¹nÕMr   c                 ó  • U R                   (       a  U R                  SX#5        U(       d=  U R                  R                  UR                  S9 nUR	                  X5      nSSS5        UR
                  (       a0  UR
                   H   u  pVU R                  R                  XV5        M"     U R                  R                  UR                  UR                  5        U R                   (       a  U R                  SX#5        U$ ! , (       d  f       N¤= f)zRun a migration backwards.Úunapply_startrp   NÚunapply_success)
r   r   rt   rq   Úunapplyr{   r   Úrecord_unappliedr}   r~   )r   rB   r6   rP   rt   r}   r~   s          r   rh   Ú#MigrationExecutor.unapply_migration  sÍ   € à×!×!Ø×"Ñ" ?°IÔDÞØ—‘×.Ñ.Ø ×'Ñ'ð /ñ àØ!×)Ñ)¨%Ó?�÷ð
 ××Ø#,×#5Ô#5‘�	Ø—‘×.Ñ.¨yÖ?ñ $6à�‰×&Ñ& y×':Ñ':¸I¿N¹NÔKà×!×!Ø×"Ñ"Ð#4°iÔFØˆ÷õ ús   ÁC>Ã>
Dc                 ó&  ^• U R                   R                  5       mU R                  R                  R	                  5        HN  u  p[        U4S jUR                   5       5      nU(       d  M-  UT;  d  M5  U R                   R                  " U6   MP     g)a¦  
Mark replacement migrations applied if their replaced set all are.

Do this unconditionally on every migrate, rather than just when
migrations are applied or unapplied, to correctly handle the case
when a new squash migration is pushed to a deployment that already had
all its replaced migrations applied. In this case no new migration will
be applied, but the applied state of the squashed migration must be
maintained.
c              3   ó,   >#   • U  H	  oT;   v •  M     g 7fr   r   )r   rc   r4   s     €r   r!   Ú7MigrationExecutor.check_replacements.<locals>.<genexpr>/  s   øé € ÐGÒ4F¨q 7žlÒ4Fùs   ƒN)r   r$   r   ÚreplacementsÚitemsrU   r{   r|   )r   rD   r6   Úall_appliedr4   s       @r   rX   Ú$MigrationExecutor.check_replacements"  sj   ø€ ð —-‘-×2Ñ2Ó4ˆØ"Ÿk™k×6Ñ6×<Ñ<Ö>‰NˆCÜÔG°I×4FÒ4FÓGÓGˆKßˆ{˜s¨'Õ1Ø—‘×,Ò,¨cÓ2ò ?r   c                 ór  ^ ^• U 4S jnTR                   c)  [        U4S jTR                   5       5      (       a  SU4$ OTR                   SL a  SU4$ Uc1  T R                  R	                  TR
                  TR                  4SS9nOTR                  U5      nUR                  nSnSnT R                  R                  R                  nT R                  R                  5        n	[        T R                  R                  R                  U	5      5      n
U(       a  U
 Vs1 s H  o»R!                  5       iM     n
nSSS5        TR"                   GHµ  n[%        U[&        R(                  5      (       a¸  UR+                  TR
                  UR                  5      nUR,                  R.                  (       a*  [0        R*                  " UR,                  R.                  5      nU" TU5      (       a  Mž  UR,                  R2                  nU(       a  UR!                  5       nUW
;  a  SU4s  $ SnMÛ  [%        U[&        R4                  5      (       d  Mü  UR+                  TR
                  UR6                  5      nUR,                  R.                  (       a*  [0        R*                  " UR,                  R.                  5      nU" TU5      (       a  GMx  UR,                  R2                  nUR,                  R9                  UR                  5      nUR:                  (       aR  UR<                  R>                  R,                  R2                  nU(       a  UR!                  5       nUW
;  a  SU4s  $ SnGM  T R                  R                  5        n	T R                  R                  RA                  XŸ5      nSSS5        W HN  nURB                  nUR                  nU(       a   UR!                  5       nUR!                  5       nUU:X  d  MJ  Sn  GM°     SU4s  $    U=(       d    UU4$ s  snf ! , (       d  f       GNç= f! , (       d  f       NŽ= f)zÏ
Test whether a migration has been implicitly applied - that the
tables or columns it would create exist. This is intended only for use
on initial migrations (as it only looks for CreateModel and AddField).
c                 ó  >• UR                   R                  =(       do    UR                   R                  (       + =(       dM    [        R                  " TR
                  R                  U R                  UR                   R                  S9(       + $ )zx
No need to detect tables for proxy models, unmanaged models, or
models that can't be migrated on the current database.
)Ú
model_name)	Ú_metaÚproxyÚmanagedr   Úallow_migrater   Úaliasr}   r�   )r6   Úmodelr   s     €r   Úshould_skip_detecting_modelÚJMigrationExecutor.detect_soft_applied.<locals>.should_skip_detecting_model:  sg   ø€ ð —‘×!Ñ!÷ Ø—{‘{×*Ñ*Ô*÷ä×+Ò+Ø—O‘O×)Ñ)Ø×'Ñ'Ø$Ÿ{™{×5Ñ5ñô ðr   Nc              3   óF   >#   • U  H  u  pUTR                   :H  v •  M     g 7fr   )r}   )r   Úappr~   r6   s      €r   r!   Ú8MigrationExecutor.detect_soft_applied.<locals>.<genexpr>K  s    øé € ÐVÒ?U±)°#�3˜)×-Ñ-Ö-Ò?Uùs   ƒ!FT)Úat_end)"ÚinitialÚanyÚdependenciesr   Úproject_stater}   r~   r@   r   r   ÚfeaturesÚignores_table_name_caseÚcursorÚsetÚintrospectionÚtable_namesÚcasefoldÚ
operationsÚ
isinstancer   ÚCreateModelÚ	get_modelr�   ÚswappedÚglobal_appsÚdb_tableÚAddFieldr�   Ú	get_fieldÚmany_to_manyÚremote_fieldÚthroughÚget_table_descriptionÚcolumn)r   rŸ   r6   r–   Úafter_stater   Úfound_create_model_migrationÚfound_add_field_migrationÚfold_identifier_caser¢   Úexisting_table_namesr~   Ú	operationr•   r­   ÚtableÚfieldÚthrough_db_tableÚcolumnsr´   Úfield_columnÚcolumn_names   ` `                   r   rs   Ú%MigrationExecutor.detect_soft_applied3  s  ù€ õ	ð ×ÑÑ$äÔV¸y×?UÒ?UÓV×VÑVØ˜mÐ+Ð+ð Wà×Ñ %Ò'à˜-Ð'Ð'àÑ ØŸ+™+×3Ñ3Ø×$Ñ$ i§n¡nÐ5¸dð 4ð ‰Kð $×0Ñ0°Ó?ˆKØ×ÑˆØ',Ð$Ø$)Ð!Ø#Ÿ™×7Ñ7×OÑOÐØ�_‰_×#Ñ#Ô%¨Ü#&Ø—‘×-Ñ-×9Ñ9¸&ÓAó$Ð ö $á0Dó(Ú0D¨—M‘M–OÑ0Dð %ð (÷ &ð #×-Õ-ˆIÜ˜)¤Z×%;Ñ%;×<Ñ<ØŸ™ y×':Ñ':¸I¿N¹NÓK�Ø—;‘;×&×&ô (×1Ò1°%·+±+×2EÑ2EÓF�EÙ.¨y¸%×@Ñ@ÙØ Ÿ;™;×/Ñ/�Þ'Ø'×0Ñ0Ó2�HØÐ#7Ó7Ø  -Ð/Ò/Ø/3Ò,Ü˜I¤z×':Ñ':×;Ó;ØŸ™ y×':Ñ':¸I×<PÑ<PÓQ�Ø—;‘;×&×&ô (×1Ò1°%·+±+×2EÑ2EÓF�EÙ.¨y¸%×@Ñ@ÚàŸ™×,Ñ,�ØŸ™×-Ñ-¨i¯n©nÓ=�ð ×%×%Ø',×'9Ñ'9×'AÑ'A×'GÑ'G×'PÑ'PÐ$Þ+Ø+;×+DÑ+DÓ+FÐ(Ø'Ð/CÓCØ$ mÐ3Ò3à48Ð1Ú Ø—_‘_×+Ñ+Ô-°Ø"Ÿo™o×;Ñ;×QÑQØó�G÷ .ó &�FØ#(§<¡<�LØ"(§+¡+�KÞ+Ø&1×&:Ñ&:Ó&<˜Ø'3×'<Ñ'<Ó'>˜Ø" lÕ2Ø48Ð1Ûñ &ð ! -Ð/Ò/ñg .ðl -×IÐ0IÈKÐWÐWùòu(÷ &Ö%ú÷\ .Õ-ús*   Ã!:PÄPÄ4PÍ:&P(ÐPÐ
P%Ð(
P6	)r   r   r   r   r   )F)NNFF)FF)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r.   rF   r[   rV   rW   ra   rw   rh   rX   rs   Ú__static_attributes__r   r   r   r   r   
   sD   † ñô
3ô1ôfô*3òjò6<ô|ò6Nôò&3õ"gXr   r   N)Údjango.apps.registryr   r¬   Ú	django.dbr   r   Ú
exceptionsr   r   r   r   r	   rB   r
   r   r   r   r   Ú<module>rË      s%   ðÝ 4ß (å ,Ý #Ý 'Ý ÷PXò PXr   