
    LȂioS                         S SK r S SKrS SKJr  S SKJr  S SKJrJrJ	r	  S SK
JrJr  S SKJrJrJr  S SKJr  S SKJr  S S	KJr  S S
KJrJr  S SKJr  S SKJr   " S S\5      rg)    N)import_module)apps)BaseCommandCommandErrorno_translations)emit_post_migrate_signalemit_pre_migrate_signal)DEFAULT_DB_ALIASconnectionsrouter)MigrationAutodetector)MigrationExecutor)AmbiguityError)
ModelStateProjectState)module_has_submodule)	Truncatorc                   f   ^  \ rS rSr\rSrS rU 4S jr\	S 5       r
S
S jrS r\S 5       rS	rU =r$ )Command   zMUpdates database schema. Manages both apps with migrations and those without.c                    UR                  SSSS9  UR                  SSSS9  UR                  SSS	S
SS9  UR                  S[        [        [        5      SS9  UR                  SSSS9  UR                  SSSS9  UR                  SSSS9  UR                  SSSS9  UR                  SSSSS9  UR                  SSSSS9  g ) N	app_label?z5App label of an application to synchronize the state.)nargshelpmigration_namezpDatabase state will be brought to the state after that migration. Use the name "zero" to unapply all migrations.z	--noinputz
--no-inputstore_falseinteractivez:Tells Django to NOT prompt the user for input of any kind.)actiondestr   z
--databasezHNominates a database to synchronize. Defaults to the "default" database.)defaultchoicesr   z--fake
store_truez5Mark migrations as run without actually running them.)r   r   z--fake-initialzDetect if tables already exist and fake-apply initial migrations if so. Make sure that the current database schema matches your initial migration before using this flag. Django will only check for an existing table name.z--planz=Shows a list of the migration actions that will be performed.z--run-syncdbz+Creates tables for apps without migrations.z--checkcheck_unappliedzbExits with a non-zero status if unapplied migrations exist and does not actually apply migrations.z--pruneprunez?Delete nonexistent migrations from the django_migrations table.)add_argumentr
   tupler   )selfparsers     XD:\sksbv-state-backend\venv\Lib\site-packages\django/core/management/commands/migrate.pyadd_argumentsCommand.add_arguments   sI   H 	 	

 	H 	 	
 	 M 	 	
 	$+& 	 	
 	H 	 	

 	'	 	 		
 	P 	 	

 	> 	 	

 	"1 	 	
 	R	 	 	
    c                 :   > [         TU ]  U5      n0 UESUS   /0E$ )N	databasesdatabase)superget_check_kwargs)r(   optionskwargs	__class__s      r*   r2   Command.get_check_kwargs\   s,    )'2=&=+
(;'<==r-   c                   ^+^, US   nUS   U l         US   U l        [        R                  " 5        H6  n[	        UR
                  S5      (       d  M   [        SUR                  5        M8     [        U   nUR                  5         [        XPR                  5      nUR                  R                  U5        UR                  R                  5       nU(       a4  SR                  S UR!                  5        5       5      n[#        SU-  5      eUS	   n	S
n
US   (       at  US   m+ [        R$                  " T+5        U	(       a)  T+UR                  R*                  ;   a  [#        ST+-  5      eO(T+UR                  R*                  ;  a  [#        ST+-  5      eUS   (       a  US   (       a  US   nUS:X  a  T+S 4/nO UR                  R-                  T+U5      nT+UR                  4nXR                  R2                  R4                  ;  aA  XR                  R6                  ;   a(  UR                  R6                  U   nUR8                  S   nU/nSn
OmUS   (       a?  UR                  R2                  R;                  5        Vs/ sH  nUS   T+:X  d  M  UPM     nnO$UR                  R2                  R;                  5       nUS   (       Ga  US   (       d  [#        S5      eU R                   S:  a0  U R<                  R?                  SU R@                  RB                  5        [E        U+4S j[G        UR                  RH                  5      [G        UR                  RJ                  5      -
   5       5      m,UR                  R6                  R!                  5        VVs/ sH.  u  nn[M        U,4S jUR8                   5       5      (       d  M,  UPM0     nnnU(       a  U R<                  R?                  U R@                  RO                  S5      5        U H)  nUu  nnU R<                  R?                  SU S U 35        M+     U R<                  R?                  U R@                  RO                  S!5      5        OT,(       a  T, H  nUu  nnU R                   S:  a9  U R<                  R?                  U R@                  RQ                  S"U S U 35      S#S$9  URR                  RU                  UU5        U R                   S:  d  M  U R<                  R?                  U R@                  RW                  S%5      5        M     O+U R                   S:  a  U R<                  R?                  S&5        URY                  U5      nUS'   (       Ga  U R<                  R?                  S(U R@                  RP                  5        U(       d  U R<                  R?                  S)5        g U H  u  nnU R<                  R?                  [)        U5      U R@                  RB                  5        URZ                   HV  nU R]                  UU5      u  nnU(       a  U R@                  R^                  OS nU R<                  R?                  SU-   U5        MX     M     US*   (       a  [`        Rb                  " S+5        g US*   (       a  U(       a  [`        Rb                  " S+5        g US   (       a  g US	   =(       a    UR                  Rd                  n	U R                   S+:  Ga  U R<                  R?                  U R@                  RC                  S,5      5        U	(       a  US   (       a8  U R<                  R?                  U R@                  RQ                  S-T+-  5      5        OcU R<                  R?                  U R@                  RQ                  S.5      S/R                  [E        UR                  Rd                  5      5      -   5        U
(       an  U R<                  R?                  U R@                  RQ                  S05      S/R                  [E        U VVs1 sH  u  nnUiM
     snn5      5      =(       d    S1-   5        OUS   S+   cG  U R<                  R?                  U R@                  RQ                  S25      [)        US   S   5      -   5        OJU R<                  R?                  U R@                  RQ                  S35      US   S+   < S4US   S   < 3-   5        URg                  S
S59nUR                  n [i        U R                   U R                  URj                  U R<                  U US69  U	(       a  U R                   S+:  a4  U R<                  R?                  U R@                  RC                  S75      5        US   (       a  U Rm                  UT+/5        O%U Rm                  XVR                  Rd                  5        U R                   S+:  a4  U R<                  R?                  U R@                  RC                  S85      5        U(       Gd'  U R                   S+:  Ga  U R<                  R?                  S95        U Ro                  UR                  Rq                  5       [r        Rt                  " [        5      5      n!U!Rw                  UR                  R2                  S:9n"U"(       a  U R<                  R?                  U R@                  RO                  S;S/R                  S< [E        U"5       5       5      -  5      5        U R<                  R?                  U R@                  RO                  S=5      5        Sn#Sn$O
US>   n#US?   n$URy                  UUUR{                  5       U#U$S@9n%U%R}                  5         U%R                  n&U&R                  5          / n'U&R                   H;  n(U(R                  U(R                  4n)U'R                  U)5        U&R                  " U)6   M=     S S S 5        U&R                  W' V*s/ sH*  n*[        R                  " [        R                  " U*6 5      PM,     sn*5        [        U R                   U R                  URj                  U R<                  U&US69  g ! [&         a  n[#        [)        U5      5      eS nAff = f! [.         a    [#        SU< ST+< S35      e[0         a    [#        SU< ST+< S35      ef = fs  snf s  snnf s  snnf ! , (       d  f       GN= fs  sn*f )ANr0   	verbosityr   
managementz.managementz; c              3   T   #    U H  u  pS R                  U5      < SU< 3v   M!     g7f), z in N)join).0appnamess      r*   	<genexpr>!Command.handle.<locals>.<genexpr>|   s$      !GXdii.4GXs   &(zConflicting migrations detected; multiple leaf nodes in the migration graph: (%s).
To fix them run 'python manage.py makemigrations --merge'
run_syncdbTr   z8Can't use run_syncdb with app '%s' as it has migrations.z"App '%s' does not have migrations.r   zeroz!More than one migration matches 'z
' in app 'z'. Please be more specific.z"Cannot find a migration matching 'z' from app 'z'.Fr   r%   z7Migrations can be pruned only when an app is specified.zPruning migrations:c              3   <   >#    U H  nUS    T:X  d  M  Uv   M     g7f)r   N )r=   	migrationr   s     r*   r@   rA      s*      "7IQ<9, 	"7s   	c              3   *   >#    U H	  oT;   v   M     g 7fNrF   )r=   replacedto_prunes     r*   r@   rA      s     S<R8+<Rs   z  Cannot use --prune because the following squashed migrations have their 'replaces' attributes and may not be recorded as applied:z    .z|  Re-run 'manage.py migrate' if they are not marked as applied, and remove 'replaces' attributes in their Migration classes.z
  Pruning  ending OKz  No migrations to prune.planzPlanned operations:z"  No planned migration operations.r$      zOperations to perform:z   Synchronize unmigrated app: %sz  Synchronize unmigrated apps: r;   z  Apply all migrations: z(none)z  Unapply all migrations: z  Target specific migration: z, from )with_applied_migrations)stdoutr   rQ   z&Synchronizing apps without migrations:zRunning migrations:z  No migrations to apply.)graphzl  Your models in app(s): %s have changes that are not yet reflected in a migration, and so won't be applied.c              3   6   #    U H  n[        U5      v   M     g 7frI   )repr)r=   r>   s     r*   r@   rA   S  s     2X499s   zk  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.fakefake_initial)rQ   staterX   rY   )Jr8   r   r   get_app_configsr   moduler   namer   prepare_databaser   migration_progress_callbackloadercheck_consistent_historydetect_conflictsr<   itemsr   get_app_configLookupErrorstrmigrated_appsget_migration_by_prefixr   KeyErrorrU   nodesreplacementsreplaces
leaf_nodesrT   writestyleMIGRATE_HEADINGsortedsetapplied_migrationsdisk_migrationsanyNOTICEMIGRATE_LABELrecorderrecord_unappliedSUCCESSmigration_plan
operationsdescribe_operationWARNINGsysexitunmigrated_apps_create_project_stater	   alias	sync_appsautodetectorproject_stater   	from_appschangesmigratecloneclear_delayed_apps_cachebulk_updatereal_modelsr   
name_lowerappendunregister_modelrender_multipler   
from_model	get_modelr   )-r(   argsr3   r0   
app_config
connectionexecutor	conflictsname_strrB   target_app_labels_onlyerrr   targetsrG   targetincomplete_migrationkeymigration_keymigration_obj4squashed_migrations_with_deleted_replaced_migrationsr>   r]   rQ   	backwards	operationmessageis_errorro   anpre_migrate_statepre_migrate_appsr   r   rX   rY   post_migrate_statepost_migrate_apps
model_keysmodel_state	model_keymodelr   rK   s-                                              @@r*   handleCommand.handle`   s   :& -"=1 ..0J#J$5$5|DDmZ__= 1
 !*
 	##%$Z1Q1QR 	00< OO446	yy !GPGX! H <>FG  \*
!%;,I-##I.  = ==&R#$  >
 (//"?"??"#G)#STT;G,<$=$%56N'%t,- ( G G!>!I $Y^^4 //"7"7"="==//">">>+3??+G+G+O(1::2>F!(%*"[!'44??AASVyEXA  G oo++668G7;'"M  ~~!!!"79S9ST !$X__%G%G!Hhoo556"7 H 5=OO4P4P4V4V4XD4X0M=SM<R<RSS 4X A D
 D!!JJ%%2 "VI )ICKK%%SE4&&9: "V !!JJ%%- %-	$-	T>>A- KK-- $

 8 8:cU!D69R S') .  !))::3E>>A- KK--djj.@.@.GH &. ^^a'KK%%&AB&&w/6??KK3TZZ5M5MN!!"FG  -1(IyKK%%c)ndjj6P6PQ%.%9%9	,0,C,C%y-) 7?

 2 2D))&7*:EB &: -1 ,-HHQK$%7 \*Nx/N/N
>>QKKdjj889QRS;'KK%%

00>J KK%%

001RS99VHOO,K,K%LMO &!!JJ,,-GHyyw(?wtq!w(?!@AMXO
 1:a=(KK%%

001MNgajm,-
 KK%%

001PQ+21:a='!*Q-HI
 %::SW:X,11NN;;!	
 ~~"!!JJ../WX {#zI;7z??+J+JK >>QKKdjj889NOP~~"!!"=>  $00OO113 **40  '..X__5J5J.KKK%%

))')-2Xw2X)XY KK%%

))* D L6?D">2L%--#))+% . 
 	335.33
 **,J0<<'11;3I3II	!!),!22I>  = - 	))HRS
uZ""4>>5#9:
S	
 	!NN;;"	
a  -"3s8,,-( & &6DiQ    &)96 "&Df )@h -, TsU    q 4r 8ss*s<ss	As.0s$
q?&q::q?<r>
s!c                    U R                   S:  Ga  U R                   S:  nUS:X  aY  U(       a  [        R                  " 5       U l        U R                  R                  SU-  SS9  U R                  R                  5         g US:X  a  U(       a%  S[        R                  " 5       U R                  -
  -  OSnU(       a8  U R                  R                  U R                  R                  SU-   5      5        g U R                  R                  U R                  R                  S	U-   5      5        g US
:X  aY  U(       a  [        R                  " 5       U l        U R                  R                  SU-  SS9  U R                  R                  5         g US:X  a  U(       a%  S[        R                  " 5       U R                  -
  -  OSnU(       a8  U R                  R                  U R                  R                  SU-   5      5        g U R                  R                  U R                  R                  S	U-   5      5        g US:X  aV  U(       a  [        R                  " 5       U l        U R                  R                  SSS9  U R                  R                  5         g US:X  af  U(       a%  S[        R                  " 5       U R                  -
  -  OSnU R                  R                  U R                  R                  SU-   5      5        g g g )NrR   apply_startz  Applying %s...rM   rN   apply_successz (%.3fs)z FAKEDrP   unapply_startz  Unapplying %s...unapply_successrender_startz  Rendering model states...render_successz DONE)	r8   time	monotonicstartrT   rn   flushro   rz   )r(   r   rG   rX   compute_timeelapseds         r*   r_   #Command.migration_progress_callback  s<   >>Q>>A-L&!%!1DJ!!"4y"@!L!!#?*DPJ$.."2TZZ"?@VX  KK%%djj&8&8G9K&LMKK%%djj&8&8&IJ?*!%!1DJ!!"6"B2!N!!#,,DPJ$.."2TZZ"?@VX  KK%%djj&8&8G9K&LMKK%%djj&8&8&IJ>)!%!1DJ!!"?!K!!#++DPJ$.."2TZZ"?@VX  !!$**"4"4Ww5F"GH	 ,C r-   c                   ^^ TR                  5        nTR                  R                  U5      mSSS5        [        R                  " 5        Vs/ sHP  nUR
                  c  M  UR                  U;   d  M$  UR                  [        R                  " UTR                  SS94PMR     nnUU4S jnU VVs0 sH  u  pxU[        [        Xh5      5      _M     n	nnU R                  S:  a  U R                  R                  S5        TR                  5        n
U	R!                  5        H  u  pxU H  nUR"                  R%                  T5      (       d  M%  U R                  S:  a8  U R                  R                  SU< S	UR"                  R&                  < S
35        U R                  S:  a2  U R                  R                  SUR"                  R(                  -  5        U
R+                  U5        M     M     U R                  S:  a  U R                  R                  S5        SSS5        g! , (       d  f       GN= fs  snf s  snnf ! , (       d  f       g= f)z;Run the old syncdb-style operation on a list of app_labels.NF)include_auto_createdc                   > U R                   nTR                  R                  nU" UR                  5      T;   =(       d<    UR                  =(       a)    U" UR                  R                   R                  5      T;   (       + $ rI   )_metaintrospectionidentifier_converterdb_tableauto_created)r   opts	converterr   tabless      r*   model_installed*Command.sync_apps.<locals>.model_installed  sk    ;;D"00EEI4==)V3 %% N!$"3"3"9"9"B"BCvM	 r-   rR   z  Creating tables...   z    Processing rL   z modelz    Creating table %sz    Running deferred SQL...)cursorr   table_namesr   r[   models_modulelabelr   get_migratable_modelsr   listfilterr8   rT   rn   schema_editorrc   r   can_migrateobject_namer   create_model)r(   r   
app_labelsr   r   
all_modelsr   app_name
model_listmanifesteditorr   r   s    `          @r*   r   Command.sync_apps  s    F--99&AF ! #224	
 5
'' 9C8H8HJ8V  ,,
 0 0u 5 	 	
		 )3
(2$ d6/>??(2 	 
 >>QKK45%%'6(0(8$'E ;;22:>> ~~*))')@)@B ~~*))3ekk6J6JJ ''. ( )9" ~~"!!"?@' ('E ! 	
,
 ('s0   H$H6"H640H62 H;DI$
H3
Ic                    SnSn[        U S5      (       a>  U(       a  U R                  OU R                  nU(       a  UR                  =(       d    SOSnO<[        U S5      (       a   U(       a  U R                  OU R
                  nOSnU(       a  SnUb  [        U5      R                  SS5      nOU(       a  SnS	nU(       a  S
U-   n[        U5      nX R                  5       -   UR                  S5      -   U4$ )z@Return a string that describes a migration operation for --plan.rM   FcodeNsqlzUndo 
IRREVERSIBLETz -> (   )hasattrreverse_coder   __doc__reverse_sqlr   rf   replacer   describechars)r   r   prefixr   r   r   	truncateds          r*   r}   Command.describe_operation  s     9f%%-69))INND-1dll(btFY&&.7Y**Y]]FF [((r2F#FHf_Ff%	**,,yr/BBHLLr-   )r   r   r8   )NF)__name__
__module____qualname____firstlineno__r   r   r   r+   r2   r   r   r_   r   staticmethodr}   __static_attributes____classcell__)r5   s   @r*   r   r      sW    (LW 	C
J> c
 c
J	&IP7Ar M Mr-   r   )r   r   	importlibr   django.appsr   django.core.management.baser   r   r   django.core.management.sqlr   r	   	django.dbr
   r   r   !django.db.migrations.autodetectorr   django.db.migrations.executorr   django.db.migrations.loaderr   django.db.migrations.stater   r   django.utils.module_loadingr   django.utils.textr   r   rF   r-   r*   <module>r     sB    
  #  R R X ; ; C ; 6 ? < 'lMk lMr-   