a
    [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   |C:\Users\91910\OneDrive\Desktop\vts_admin_rebuild-master\vts\Lib\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rt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   