
     +h[                         d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZmZ d dlmZ d dlmZ d d	lmZ d d
lmZ dZdZ G d de          ZdS )    N)
itemgetter)Path)call_command)BaseCommandCommandError)DEFAULT_DB_ALIASconnections)MigrationLoader)MigrationRecorder)timezone)signalcommandzmanagestate.jsondefaultc                       e Zd ZU dZdxZZdZeed<   eed<   e	ed<   e
ed<   d Zed             Zd	e	fd
Zd	e	fdZdefdZdefdZde	de	defdZdefdZdefdZdS )Commandz,Manage database state in the convenient way.Nmigrate_argsmigrate_optionsfilename	verbosityc                 F   |                     ddd           |                     ddt          dt           d	           |                     d
dt          dt           d           |                     ddt          dt           d           |                     ddddd           |                     ddd           |                     ddd           |                     ddd           |                     d dd!           |                     d"dd#d$           d S )%Naction)dumploadztAn action to do. Dump action saves applied migrations to a file. Load action applies migrations specified in a file.)choiceshelpstate?z@A name of a state. Usually a name of a git branch. Defaults to "")nargsr   r   z-dz
--databasez6Nominates a database to synchronize. Defaults to the "z" database.)r   r   z-fz
--filenamez!A file to write to. Defaults to "z	--noinputz
--no-inputstore_falseinteractivez^The argument for "migrate" command. Tells Django to NOT prompt the user for input of any kind.)r   destr   z--fake
store_truezYThe argument for "migrate" command. Mark migrations as run without actually running them.)r   r   z--fake-initiala   The argument for "migrate" command. Detect 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--planzaThe argument for "migrate" command. Shows a list of the migration actions that will be performed.z--run-syncdbzOThe argument for "migrate" command. Creates tables for apps without migrations.z--checkcheck_unappliedz_The argument for "migrate" command. Exits with a non-zero status if unapplied migrations exist.)add_argumentDEFAULT_STATEr   DEFAULT_FILENAME)selfparsers     u/var/www/html/e360mart/e360mart_env/lib/python3.11/site-packages/django_extensions/management/commands/managestate.pyadd_argumentszCommand.add_arguments   s   .G 	 	
 	
 	
 	3dTaddd 	 	
 	
 	
 	,(8gJZggg 	 	
 	
 	
 	,(8H5EHHH 	 	
 	
 	
 	m-N 	 	
 	
 	

 	\I 	 	
 	
 	

 	\L 	 	
 	
 	
 	\Q 	 	
 	
 	

 	<? 	 	
 	
 	

 	l1BO 	 	
 	
 	
 	
 	
    c                     || _         || _        |d         | _        t          |         | _        || _        || _         t          | |          |           d S )Nr   )r   r   r   r	   conndatabaser   getattr)r'   r   r.   r   r   argsoptionss          r)   handlezCommand.handleR   sX     & -)	  fe$$$$$r+   r   c           	      &   |                                  }|                    |                                            |                     ||i           | j                            | j                            d| d| j         d                     dS )z"Save applied migrations to a file.zMigrations for state "z"" have been successfully saved to .N)get_migrated_appsupdateget_applied_migrationswritestdoutstyleSUCCESSr   )r'   r   migrated_appss      r)   r   zCommand.dump\   s    ..00T88::;;;

E=)***$*,,^U^^dm^^^
 
 	 	 	 	 	r+   c                 T   |                                                      |          }|t          d|           i | j        | j        | j        dk    r
| j        dz
  ndd}|                                D ]y\  }}|                     ||          r| j        dk    r6| j        	                    | j
                            d| d                     ||g| j        R }t          dg|R i | z| j        	                    | j
                            d	| d
                     dS )zApply migrations from a file.NzNo such state saved:    r   )r.   r   zApplying migrations for "r   migrateMigrations for "z!" have been successfully applied.)readgetr   r   r.   r   items
is_appliedr9   r8   r:   WARNINGr   r   r;   )r'   r   
migrationskwargsapp	migrationr0   s          r)   r   zCommand.loade   so   YY[[__U++
>u>>???
"
/3~/A/A!++q
 
 
 )..00 	5 	5NCsI.. ~!!!!$*"4"45WQT5W5W5W"X"XYYY7T%677D4T444V4444$*,,GuGGG
 
 	 	 	 	 	r+   returnc                     t          | j                  j        }t                              |d          }| j        dk    r=| j                            dd                    t          |                    z              |S )z!Installed apps having migrations.zeror>   zApps having migrations: z, )
r
   r-   r<   dictfromkeysr   r9   r8   joinsorted)r'   appsr<   s      r)   r5   zCommand.get_migrated_apps~   sj    ty))7dF33>AK8499VMEZEZ;[;[[\\\r+   c                     | j         r| j         S t          | j                                                  }t	          |                                t          d                    }t          |          | _         | j         S )z,Installed apps with last applied migrations.r>   )key)_applied_migrationsr   r-   applied_migrationsrP   keysr   rM   )r'   rF   last_applieds      r)   r7   zCommand.get_applied_migrations   sl    # 	,++&ty11DDFF
joo//Z]]CCC#'#5#5 ''r+   rH   rI   c                     |                                                      |          }||k    rC| j        dk    r6| j                            | j                            d| d                     dS dS )z7Check whether a migration for an app is applied or not.r>   r@   z" are already applied.TF)r7   rB   r   r9   r8   r:   rE   )r'   rH   rI   applieds       r)   rD   zCommand.is_applied   s    --//33C88i~!!!!$*"4"4BsBBB# #    4ur+   c                 ,   t          | j                  }|                                r|                                st	          d| j                   t          | j                  5 }t          j        |          cddd           S # 1 swxY w Y   dS )zGet saved state from the file.zNo such file: N)r   r   existsis_filer   openjsonr   )r'   pathfiles      r)   rA   zCommand.read   s    DM""{{}} 	ADLLNN 	A???@@@$-   	#D9T??	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   (B		BBdatac                 L   	 |                                  }n# t          $ r i }Y nw xY w|                    |t          t	          j                                         t          | j        d          5 }t          j	        ||dd           ddd           dS # 1 swxY w Y   dS )z.Write new data to the file using existent one.)
updated_atw   T)indent	sort_keysN)
rA   r   r6   strr   nowr]   r   r^   r   )r'   ra   savedr`   s       r)   r8   zCommand.write   s    	IIKKEE 	 	 	EEE	 	Tc(,..&9&9:::$-%% 	=IeT!t<<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=s    &&3BB B)__name__
__module____qualname__r   r-   r.   rT   rM   __annotations__rh   intr*   r   r2   r   r   r5   r7   boolrD   rA   r8    r+   r)   r   r      sK        9DD8MMMNNN4
 4
 4
l % % ]%#    #    24    	( 	( 	( 	( 	(	c 	c 	d 	 	 	 	#d # # # #	=$ 	= 	= 	= 	= 	= 	=r+   r   )r^   operatorr   pathlibr   django.core.managementr   django.core.management.baser   r   	django.dbr   r	   django.db.migrations.loaderr
   django.db.migrations.recorderr   django.utilsr   "django_extensions.management.utilsr   r&   r%   r   rq   r+   r)   <module>r{      s                / / / / / / A A A A A A A A 3 3 3 3 3 3 3 3 7 7 7 7 7 7 ; ; ; ; ; ; ! ! ! ! ! ! < < < < < <% [= [= [= [= [=k [= [= [= [= [=r+   