
    Vh                     V    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e      Zy)    )apps)BaseCommandCommandError)DEFAULT_DB_ALIASconnections)AmbiguityErrorMigrationLoaderc                   2     e Zd ZdZdZd Z fdZd Z xZS )Commandz2Prints the SQL statements for the named migration.Tc                     |j                  dd       |j                  dd       |j                  dt        t        t              d       |j                  d	d
d       y )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.)defaultchoicesr   z--backwards
store_truez=Creates SQL to unapply the migration, rather than to apply it)actionr   )add_argumentr   tupler   )selfparsers     Z/home/dcms/DCMS/lib/python3.12/site-packages/django/core/management/commands/sqlmigrate.pyadd_argumentszCommand.add_arguments   s|    V 	 	
 	#I 	 	
 	$+& 	 	
 	P 	 	
    c                 F    d | j                   _        t        |   |i |S )Nc                     | S )N )noops    r   <lambda>z!Command.execute.<locals>.<lambda>%   s    d r   )styleSQL_KEYWORDsuperexecute)r   argsoptions	__class__s      r   r#   zCommand.execute"   s%     "3

w000r   c                    t         |d      }t        |d      }|d   |d   }}	 t        j                  |       ||j                  vrt        d|z        	 |j                  ||      }||j                  f}	|j                  xr |j                  j                  | _        |j                   j"                  |	   |d   fg}
|j%                  |
      }|s#|d   dk\  r| j&                  j)                  d       dj+                  |      S # t        $ r}t        t        |            d }~ww xY w# t        $ r t        d|d|d	      t        $ r t        d
|d|d      w xY w)NdatabaseF)replace_migrationsr   r   z!App '%s' does not have migrationsz!More than one migration matches 'z
' in app 'z'. Please be more specific.z"Cannot find a migration matching 'z' from app 'z'. Is it in INSTALLED_APPS?	backwards	verbosity   zNo operations found.
)r   r	   r   get_app_configLookupErrorr   strmigrated_appsget_migration_by_prefixr   KeyErrornameatomicfeaturescan_rollback_ddloutput_transactiongraphnodescollect_sqlstderrwritejoin)r   r$   r%   
connectionloaderr   r   err	migrationtargetplansql_statementss               r   handlezCommand.handle(   s    !45
 !F %,K$8'BR:S>		)	* F000BYNOO	66y.QI Y^^,
 E!4!4!E!E 	 ##F+W[-ABC++D1'+"6!";KK45yy((=  	)s3x((	)  	-y:   	%3Y@ 	s#   D D+ 	D(D##D(+6E!)	__name__
__module____qualname__r   r8   r   r#   rF   __classcell__)r&   s   @r   r   r      s    ?D
,1+)r   r   N)django.appsr   django.core.management.baser   r   	django.dbr   r   django.db.migrations.loaderr   r	   r   r   r   r   <module>rO      s     A 3 GL)k L)r   