a
    Lcòfm*  ã                   @   s¬   d dl Z 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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 G dd„ deƒZdS )é    N)Úapps)Úsettings)ÚBaseCommandÚCommandError)Úrun_formatters)ÚDEFAULT_DB_ALIASÚconnectionsÚ
migrations)ÚAmbiguityErrorÚMigrationLoader)ÚSwappableTuple)ÚMigrationOptimizer)ÚMigrationWriter)Úget_docs_versionc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚCommandzZSquashes an existing set of migrations (from first until specified) into a single new one.c                 C   st   |j ddd� |j dddd� |j dd	d� |j d
ddd� |j dddddd� |j ddd� |j ddddd� d S )NÚ	app_labelz6App label of the application to squash migrations for.)ÚhelpÚstart_migration_nameú?zGMigrations will be squashed starting from and including this migration.)Únargsr   Úmigration_namez?Migrations will be squashed until and including this migration.z--no-optimizeÚ
store_truez/Do not try to optimize the squashed operations.)Úactionr   z	--noinputz
--no-inputÚstore_falseÚinteractivez:Tells Django to NOT prompt the user for input of any kind.)r   Údestr   z--squashed-namez,Sets the name of the new squashed migration.z--no-headerÚinclude_headerz:Do not add a header comment to the new squashed migration.)Úadd_argument)ÚselfÚparser© r    úm/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/django/core/management/commands/squashmigrations.pyÚadd_arguments   sF    þüþýûþüzCommand.add_argumentsc              
      sÀ  |d | _ |d | _|d }|d }|d }|d }|d }|d }zt |¡ W n0 ty‚ } ztt|ƒƒ‚W Y d }~n
d }~0 0 ttt	 ƒ‰ |ˆ j
vr¦td	| ƒ‚|  ˆ ||¡‰‡ ‡fd
d„ˆ j ˆjˆjf¡D ƒ}	|�r>|  ˆ ||¡}
ˆ  |
j|
j¡}z|	 |¡}|	|d … }	W n& t�y<   td|
ˆ|f ƒ‚Y n0 | j dk�sR| j�rÖ| j | j d¡¡ |	D ]‰| j dˆj ¡ �qj| j�rÖd }|�r |dv�rÈtdƒ}|�s¸d}�qÈn|d  ¡ }�q�|dk�rÖd S g }tƒ }d}|	D ]Œ}|j�rtdtƒ  ƒ‚| |j¡ |jD ]X}t|t ƒ�rJt!j"|j#k�r>| $d¡ n
| $|¡ n |d |jk�s`|�r| $|¡ �qd}�qè|�r¢| j dk�rœ| j | j d¡¡ |}n|| j dk�rÂ| j | j d¡¡ t%ƒ }| &|ˆj¡}| j dk�rt'|ƒt'|ƒk�r| j d¡ n| j dt'|ƒt'|ƒf ¡ g }|	D ].‰ˆj�r@| ˆj¡ n| (ˆjˆjf¡ �q&t)dt*j+f|||dœƒ}|�r¶|�rš|
j ,dd¡\}}d ||f }nd!|
jˆjf }|||ƒ}n$d"|�pÆd#ˆj  }|||ƒ}d|_-t.||ƒ}t/j0 1|j0¡�rtd$|j› d%�ƒ‚t2|j0d&d'd(��}| | 3¡ ¡ W d   ƒ n1 �s<0    Y  t4|j0gƒ | j dk�r¼| j | j d)|j0 ¡d* ¡ |j5�r¼| j | j d+¡d, ¡ t6 7d-¡�r¼| j | j 8d.¡¡ d S )/NÚ	verbosityr   r   r   r   Úno_optimizeÚsquashed_namer   zLApp '%s' does not have migrations (so squashmigrations on it makes no sense)c                    s&   g | ]\}}|ˆj krˆ  ||¡‘qS r    )r   Úget_migration)Ú.0ÚalÚmn©ÚloaderZ	migrationr    r!   Ú
<listcomp>X   s   
üz"Command.handle.<locals>.<listcomp>z–The migration '%s' cannot be found. Maybe it comes after the migration '%s'?
Have a look at:
  python manage.py showmigrations %s
to debug this issue.r   z%Will squash the following migrations:z - %sZynzDo you wish to proceed? [yN] ÚnÚyTz¥You cannot squash squashed migrations! Please transition it to a normal migration first: https://docs.djangoproject.com/en/%s/topics/migrations/#squashing-migrations)Z__setting__ÚAUTH_USER_MODELFz(Skipping optimization.)zOptimizing...z  No optimizations possible.z0  Optimized from %s operations to %s operations.Ú	Migration)ÚdependenciesÚ
operationsÚreplacesÚ_é   z%s_%sz%s_squashed_%sz0001_%szsquashed_%sz
Migration z& already exists. Use a different name.Úwzutf-8)Úencodingz!Created new squashed migration %szê
  You should commit this migration but leave the old ones in place;
  the new migration will be used for new installs. Once you are sure
  all instances of the codebase have applied the migrations you squashed,
  you can delete them.zManual porting requiredzÁ
  Your migrations contained functions that must be manually copied over,
  as we could not safely copy their implementation.
  See the comment at the top of the squashed migration for details.Úblackz]Squashed migration couldn't be formatted using the "black" command. You can call it manually.)9r#   r   r   Zget_app_configÚLookupErrorr   Ústrr   r   r   Zmigrated_appsÚfind_migrationÚgraphZforwards_planr   Únamer&   ÚindexÚ
ValueErrorÚstdoutÚwriteÚstyleZMIGRATE_HEADINGÚinputÚlowerÚsetr3   r   Úextendr2   r1   Ú
isinstancer   r   r/   ZsettingÚaddr   ÚoptimizeÚlenÚappendÚtyper	   r0   ÚsplitÚinitialr   ÚosÚpathÚexistsÚopenÚ	as_stringr   Zneeds_manual_portingÚshutilÚwhichÚWARNING)r   Úoptionsr   r   r   r$   r%   r   ÚerrZmigrations_to_squashZstart_migrationÚstartÚstart_indexZanswerr2   r1   Zfirst_migrationZ
smigrationÚ
dependencyZnew_operationsZ	optimizerr3   ÚsubclassÚprefixr4   r=   Znew_migrationÚwriterÚfhr    r*   r!   Úhandle>   s   

"
ÿÿ
ÿþÿÿ
üÿ
	
ÿ
þÿ

ÿÿÿýý	

ÿ.ÿýÿÿÿÿzCommand.handlec                 C   sV   z|  ||¡W S  ty0   td||f ƒ‚Y n" tyP   td||f ƒ‚Y n0 d S )NzJMore than one migration matches '%s' in app '%s'. Please be more specific.z4Cannot find a migration matching '%s' from app '%s'.)Zget_migration_by_prefixr
   r   ÚKeyError)r   r+   r   r=   r    r    r!   r;   ÿ   s    ÿÿÿÿzCommand.find_migrationN)Ú__name__Ú
__module__Ú__qualname__r   r"   r`   r;   r    r    r    r!   r      s   ÿ( Br   )rO   rT   Zdjango.appsr   Zdjango.confr   Zdjango.core.management.baser   r   Zdjango.core.management.utilsr   Z	django.dbr   r   r	   Zdjango.db.migrations.loaderr
   r   Zdjango.db.migrations.migrationr   Zdjango.db.migrations.optimizerr   Zdjango.db.migrations.writerr   Zdjango.utils.versionr   r   r    r    r    r!   Ú<module>   s   