
    df                     j    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dS )	    N)apps)BaseCommand)DEFAULT_DB_ALIASconnections)MigrationLoader)MigrationRecorderc                   4    e Zd ZdZd Zd Zd ZddZddZdS )	Commandz6Shows all available migrations for the current projectc                 0   |                     ddd           |                     dt          d           |                                }|                     dd	d
ddd           |                     ddd
ddd           |                    d           d S )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.)defaultr   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   add_mutually_exclusive_groupset_defaults)selfparserformatss      jD:\Python Project\djangoTemplates\venv\Lib\site-packages\django/core/management/commands/showmigrations.pyadd_argumentszCommand.add_arguments   s    E 	 	
 	
 	

 	$&	 	 	
 	
 	
 5577 $ 	 	
 	
 	
 	 F 	 	
 	
 	
 	6*****    c                     |d         | _         |d         }t          |         }|d         dk    r|                     ||d                   S |                     ||d                   S )N	verbositydatabaser   r   r   )r"   r   	show_plan	show_list)r   argsoptionsdb
connections        r   handlezCommand.handle8   se     - Z  _
8&&>>*gk.BCCC>>*gk.BCCCr    c                     d}|D ]W}	 t          j        |           # t          $ r3}| j                            t          |                     d}Y d }~Pd }~ww xY w|rt          j        d           d S d S )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_namesD   s    ! 	% 	%H%#H---- % % %!!#c((+++ $%  	HQKKKKK	 	s   
A)AANc           	         t          |d          }t          |          }|                                }|j        }|r|                     ||           nt          |j                  }|D ]}| j                            || j	        j
                   t                      }|                    |          D ]%}	|                    |	          D ]}
|
|vr|
d         |k    r|
d         }|j        |
         j        r%|dt!          |j        |
         j                  z  z  }|j                            |
          }|rj|
|v rd|z  }n
|dz  }d|z  }| j        d	k    r0t'          |d
          r |d|j                            d          z  z  }| j                            |           n| j                            d|z             |                    |
           '|s%| j                            d| j	        j                   dS )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graphr9   sortedmigrated_appsstdoutr0   styleMIGRATE_LABELset
leaf_nodesforwards_plannodesreplaceslengetr"   hasattrr=   strftimeaddERROR)r   r)   r5   r4   recorderrecorded_migrationsr?   r7   shownnode	plan_nodetitleapplied_migrationoutputs                 r   r%   zCommand.show_listO   se    !$GGG$Z00&99;; 	5$$VY7777 v344I " #	H #	HHKh
(@AAAEEE((22 - -!&!4!4T!:!: - -I --)A,(2J2J )! ;y1: !%@3 %I 6 ?D D & E -3,E,I,I),T,T), A(,???)2U): %)X X)2U):#~22w 198 82 !'$6&7&?&H&H(;'& '&%&!" !K--f5555 K--i%.?@@@		),,,9-<  H!!"4dj6FGGGG#	H #	Hr    c                 .   t          |          }|j        }r7|                     |           fd|                                D             }n|                                }g }t	                      }|D ]U}|                    |          D ]=}	|	|vr7|j        |	         }
|                    |
           |                    |	           >Vd }|D ]}
d}| j	        dk    r ||
          }|
j
        |j        v r9| j                            d|
j
        d         d|
j
        d         |           a| j                            d	|
j
        d         d|
j
        d         |           |s'| j                            d
| j        j                   dS dS )z
        Show all known migrations (or only those of the specified app_names)
        in the order they will be applied.
        c                 (    g | ]}|d          v |S )r    ).0keyr5   s     r   
<listcomp>z%Command.show_plan.<locals>.<listcomp>   s'    PPPsCFi<O<Os<O<O<Or    c                     g }t          | j                  D ]}|                    d|j        z              |rdd                    |          z  S dS )Nz%s.%sz	 ... (%s)z,  )r@   parentsappendr\   join)rS   outparents      r   
print_depsz%Command.show_plan.<locals>.print_deps   s^    C .. 1 1

7VZ/0000 4"TYYs^^332r    r_   r,   z[X]  r   .r<   z[ ]  z(no migrations)N)r   r?   r9   rF   rE   rG   node_mapra   rN   r"   r\   r>   rB   r0   rC   rO   )r   r)   r5   r4   r?   targetsr   seentarget	migrationrS   re   depss     `          r   r$   zCommand.show_plan   s    !,, 	)$$VY777PPPPe&6&6&8&8PPPGG&&((Guu  	( 	(F"0088 ( (	D(( >)4DKK%%%HHY'''	(	 	 	  	U 	UDD~""!z$''x6444!!!DHQKKK!dd"STTTT!!!DHQKKK!dd"STTTT 	CK/1ABBBBB	C 	Cr    )N)	__name__
__module____qualname__r   r   r*   r9   r%   r$   rZ   r    r   r
   r
   
   s}        CD)+ )+ )+V
D 
D 
D	 	 	5H 5H 5H 5Hn*C *C *C *C *C *Cr    r
   )r2   django.appsr   django.core.management.baser   	django.dbr   r   django.db.migrations.loaderr   django.db.migrations.recorderr   r
   rZ   r    r   <module>ru      s    



       3 3 3 3 3 3 3 3 3 3 3 3 3 3 7 7 7 7 7 7 ; ; ; ; ; ;fC fC fC fC fCk fC fC fC fC fCr    