
    Vh                     b    d dl Z d dlmZ d dlmZ d dlmZmZ d dlm	Z	 d dl
mZ  G d de      Zy)	    N)apps)BaseCommand)DEFAULT_DB_ALIASconnections)MigrationLoader)MigrationRecorderc                   2    e Zd ZdZd Zd Zd ZddZddZy)	Commandz6Shows all available migrations for the current projectc                    |j                  ddd       |j                  dt        t        t              d       |j	                         }|j                  dd	d
ddd       |j                  ddd
ddd       |j                  d       y )N	app_label*z2App labels of applications to limit the output to.)nargshelpz
--databasezPNominates a database to show migrations for. Defaults to the "default" database.)defaultchoicesr   z--listz-lstore_constformatlistzShows a list of all migrations and which are applied. With a verbosity level of 2 or above, the applied datetimes will be included.)actiondestconstr   z--planz-pplanzShows all migrations in the order they will be applied. With a verbosity level of 2 or above all direct migration dependencies and reverse dependencies (run_before) will be included.)r   )add_argumentr   tupler   add_mutually_exclusive_groupset_defaults)selfparserformatss      ^/home/dcms/DCMS/lib/python3.12/site-packages/django/core/management/commands/showmigrations.pyadd_argumentszCommand.add_arguments   s    E 	 	

 	$+&& 	 	
 557 $ 	 	
 	 F 	 	
 	6*    c                     |d   | _         |d   }t        |   }|d   dk(  r| j                  ||d         S | j                  ||d         S )N	verbositydatabaser   r   r   )r$   r   	show_plan	show_list)r   argsoptionsdb
connections        r    handlezCommand.handle9   s\     - Z  _
8&>>*gk.BCC>>*gk.BCCr"   c                     d}|D ]  }	 t        j                  |        |rt        j                  d       y y # t        $ r0}| j                  j	                  t        |             d}Y d }~hd }~ww xY w)NFT   )r   get_app_configLookupErrorstderrwritestrsysexit)r   loader	app_nameshas_bad_namesapp_nameerrs         r    _validate_app_nameszCommand._validate_app_namesE   sk    ! 	%H%##H-	% HHQK   %!!#c(+ $%s   9	A2&A--A2Nc           	      &   t        |d      }t        |      }|j                         }|j                  }|r| j	                  ||       nt        |j                        }|D ]  }| j                  j                  || j                  j                         t               }|j                  |      D ]'  }	|j                  |	      D ]  }
|
|vs	|
d   |k(  s|
d   }|j                  |
   j                  r(|dt!        |j                  |
   j                        z  z  }|j                  j#                  |
      }|rl|
|v rd|z  }n
|dz  }d|z  }| j$                  d	k\  r-t'        |d
      r!|d|j(                  j+                  d      z  z  }| j                  j                  |       n| j                  j                  d|z         |j-                  |
        * |r~| j                  j                  d| j                  j.                          y)zh
        Show a list of all migrations on the system, or only those of
        some named apps.
        T)ignore_no_migrationsr      z (%s squashed migrations)z [X] %sz- Run 'manage.py migrate' to finish recording.z [-] %sr.   appliedz (applied at %s)z%Y-%m-%d %H:%M:%Sz [ ] %sz (no migrations)N)r   r   applied_migrationsgraphr;   sortedmigrated_appsstdoutr2   styleMIGRATE_LABELset
leaf_nodesforwards_plannodesreplaceslengetr$   hasattrr?   strftimeaddERROR)r   r+   r7   r6   recorderrecorded_migrationsrA   r9   shownnode	plan_nodetitleapplied_migrationoutputs                 r    r'   zCommand.show_listP   s     !$G$Z0&99;$$VY7 v334I " #	HHKKh

(@(@AEE((2 -!&!4!4T!: -I -)A,(2J )! ;;y1::!%@3 %I 6 ? ?D & E -3,E,E,I,I),T),(,??)2U): %)X X)2U):#~~2w 198 !'$6&7&?&?&H&H(;'&%&!" !KK--f5 KK--i%.?@		),9--> !!"4djj6F6FGG#	Hr"   c                 `   t        |      }|j                  }|r8| j                  ||       |j                         D cg c]  }|d   |v s| }}n|j                         }g }t	               }|D ]N  }	|j                  |	      D ]8  }
|
|vs|j                  |
   }|j                  |       |j                  |
       : P d }|D ]  }d}| j                  dk\  r ||      }|j                  |j                  v r>| j                  j                  d|j                  d   d|j                  d   |       r| j                  j                  d|j                  d   d|j                  d   |        |s1| j                  j                  d	| j                  j                         y
y
c c}w )z
        Show all known migrations (or only those of the specified app_names)
        in the order they will be applied.
        r   c                     g }t        | j                        D ]   }|j                  d|j                  z         " |rddj	                  |      z  S y)Nz%s.%sz	 ... (%s)z,  )rB   parentsappendkeyjoin)rU   outparents      r    
print_depsz%Command.show_plan.<locals>.print_deps   sM    C . 1

7VZZ/01"TYYs^33r"   r\   r.   z[X]  .r>   z[ ]  z(no migrations)N)r   rA   r;   rH   rG   rI   node_mapr^   rP   r$   r_   r@   rD   r2   rE   rQ   )r   r+   r7   r6   rA   r_   targetsr   seentarget	migrationrU   rc   depss                 r    r&   zCommand.show_plan   s    !,$$VY7&+&6&6&8PsCFi<OsPGP&&(Gu  	(F"008 (	D( >>)4DKK%HHY'	(	(	  	UDD~~"!$'xx6444!!DHHQK!d"ST!!DHHQK!d"ST	U KK/1A1AB ? Qs   F+F+)N)	__name__
__module____qualname__r   r!   r,   r;   r'   r&    r"   r    r
   r
   
   s%    CD*+X
D	5Hn*Cr"   r
   )r4   django.appsr   django.core.management.baser   	django.dbr   r   django.db.migrations.loaderr   django.db.migrations.recorderr   r
   rn   r"   r    <module>rt      s'    
  3 3 7 ;gCk gCr"   