a
    Lcòfì  ã                   @   sP   d dl mZ d dlmZmZ d dlmZmZ d dlm	Z	m
Z
 G dd„ deƒZdS )é    )Úapps)ÚBaseCommandÚCommandError)ÚDEFAULT_DB_ALIASÚconnections)ÚAmbiguityErrorÚMigrationLoaderc                       s4   e Zd ZdZdZdd„ Z‡ fdd„Zdd„ Z‡  ZS )	ÚCommandz2Prints the SQL statements for the named migration.Tc                 C   s@   |j ddd� |j ddd� |j dtdd� |j d	d
dd� d S )NÚ	app_labelz6App label of the application containing the migration.)ÚhelpÚmigration_namez$Migration name to print the SQL for.z
--databasezKNominates a database to create SQL for. Defaults to the "default" database.)Údefaultr   z--backwardsÚ
store_truez=Creates SQL to unapply the migration, rather than to apply it)Úactionr   )Úadd_argumentr   )ÚselfÚparser© r   úg/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/django/core/management/commands/sqlmigrate.pyÚadd_arguments   s     ÿÿüýzCommand.add_argumentsc                    s   d|d< t ƒ j|i |¤ŽS )NTÚno_color)ÚsuperÚexecute)r   ÚargsÚoptions©Ú	__class__r   r   r   !   s    zCommand.executec              
   O   s8  t |d  }t|dd�}|d |d  }}zt |¡ W n0 tyh } ztt|ƒƒ‚W Y d }~n
d }~0 0 ||jvr€td| ƒ‚z| ||¡}W nB t	y²   td||f ƒ‚Y n" t
yÒ   td||f ƒ‚Y n0 ||jf}	|joê|jj| _|jj|	 |d	 fg}
| |
¡}|�s.|d
 dk�r.| j d¡ d |¡S )NZdatabaseF)Zreplace_migrationsr
   r   z!App '%s' does not have migrationszJMore than one migration matches '%s' in app '%s'. Please be more specific.zMCannot find a migration matching '%s' from app '%s'. Is it in INSTALLED_APPS?Z	backwardsÚ	verbosityé   zNo operations found.Ú
)r   r   r   Zget_app_configÚLookupErrorr   ÚstrZmigrated_appsZget_migration_by_prefixr   ÚKeyErrorÚnameZatomicÚfeaturesZcan_rollback_ddlÚoutput_transactionÚgraphÚnodesZcollect_sqlÚstderrÚwriteÚjoin)r   r   r   Ú
connectionÚloaderr
   r   ÚerrZ	migrationÚtargetZplanZsql_statementsr   r   r   Úhandle(   s>    "
ÿÿÿÿ

ÿ
zCommand.handle)	Ú__name__Ú
__module__Ú__qualname__r   r%   r   r   r/   Ú__classcell__r   r   r   r   r	      s
   r	   N)Zdjango.appsr   Zdjango.core.management.baser   r   Z	django.dbr   r   Zdjango.db.migrations.loaderr   r   r	   r   r   r   r   Ú<module>   s   