https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/django/db/migrations/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/django/db/migrations/__pycache__/autodetector.cpython-310.pyc
o

3�a���@s�ddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZdd
lmZmZddlmZGdd
�d
�ZdS)�N)�chain)�settings)�models)�
operations)�	Migration)�AlterModelOptions)�MigrationOptimizer)�MigrationQuestioner)�COMPILED_REGEX_TYPE�RegexObject)�stable_topological_sortc@steZdZdZdXdd�ZdYdd�Zdd�Zd	d
�ZdZdd�Zd
d�Z	dd�Z
edd��ZdXdd�Z
dd�Zdd�Zdd�Zd[dd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dJdK�Z(dLdM�Z)dNdO�Z*dPdQ�Z+dXdRdS�Z,dTdU�Z-e.dVdW��Z/dS)\�MigrationAutodetectora

    Take a pair of ProjectStates and compare them to see what the first would
    need doing to make it match the second (the second usually being the
    project's current state).

    Note that this naturally operates on entire projects at a time,
    as it's likely that changes interact (for example, you can't
    add a ForeignKey without having a migration to add the table it
    depends on first). A user interface may offer single-app usage
    if it wishes, with the caveat that it may not always be possible.
    NcCs.||_||_|p
t�|_dd�|jD�|_dS)NcSsh|]\}}|�qS�r)�.0�app�modelrr�C/usr/lib/python3/dist-packages/django/db/migrations/autodetector.py�	<setcomp>!�z1MigrationAutodetector.__init__.<locals>.<setcomp>)�
from_state�to_stater	�
questionerr�
existing_apps)�selfrrrrrr�__init__szMigrationAutodetector.__init__cCs.|�||�}|�|||�}|r|�||�}|S)z�
        Main entry point to produce a list of applicable changes.
        Take a graph to base names on and an optional set of apps
        to try and restrict to (restriction is not guaranteed)
        )�_detect_changes�arrange_for_graph�
_trim_to_apps)r�graph�trim_to_apps�convert_apps�migration_name�changesrrrr"#s
zMigrationAutodetector.changescst|t�r�fdd�|D�St|t�rt�fdd�|D��St|t�r.�fdd�|��D�St|tj�rB|j��|j	���|j
�fSt|t�rKt|�St|t
�rR|St|d�r�|��}t|tj�rg|dd	�}|\}}}|�fd
d�|D��fdd�|��D�fS|S)z�
        Recursive deconstruction for a field and its arguments.
        Used for full comparison for rename/alter; sometimes a single-level
        deconstruction will not compare correctly.
        c�g|]}��|��qSr��deep_deconstruct�r�value�rrr�
<listcomp>6�z:MigrationAutodetector.deep_deconstruct.<locals>.<listcomp>c3s�|]}��|�VqdS�Nr$r&r(rr�	<genexpr>8s�z9MigrationAutodetector.deep_deconstruct.<locals>.<genexpr>c�i|]
\}}|��|��qSrr$�r�keyr'r(rr�
<dictcomp>:�
��z:MigrationAutodetector.deep_deconstruct.<locals>.<dictcomp>�deconstruct�Ncr#rr$r&r(rrr)Nr*cr-rr$r.r(rrr0Or1)�
isinstance�list�tuple�dict�items�	functools�partial�funcr%�args�keywordsr
r�type�hasattrr2r�Field)r�obj�
deconstructed�pathr<�kwargsrr(rr%/s4



�




��	z&MigrationAutodetector.deep_deconstructcCsJg}t|���D]\}}|�|�}|jr|jjr|dd=|�|�q|S)z�
        Return a definition of the fields that ignores field names and
        what related fields actually relate to. Used for detecting renames (as
        the related fields change during renames).
        ��to)�sortedr8r%�remote_fieldr�append)r�fields�
fields_def�name�field�deconstructionrrr�only_relation_agnostic_fieldsWs

z3MigrationAutodetector.only_relation_agnostic_fieldscCsi|_i|_i|_|jj|_|jj|_t	�|_
t	�|_t	�|_t	�|_
t	�|_t	�|_|jjD]3\}}|j�||�}|jjsG|j�||f�q/||jjvrb|jjrZ|j�||f�q/|j
�||f�q/|jjD]9\}}|j�||�}|jjs|j�||f�qg||jjvs�|r�||vr�|jjr�|j�||f�qg|j
�||f�qg|��|��|��|��|��|��|��|��|��|� �|�!�|�"�|�#�|�$�|�%�|�&�|�'�|�(�|�)�|�*�|�+�|�,�|�-�|�.�|�/|�|�0�|j1S)aX
        Return a dict of migration plans which will achieve the
        change from from_state to to_state. The dict has app labels
        as keys and a list of migrations as values.

        The resulting migrations aren't specially named, but the names
        do matter for dependencies inside the set.

        convert_apps is the list of apps to convert to use migrations
        (i.e. to make initial migrations for, in the usual case)

        graph is an optional argument that, if provided, can help improve
        dependency generation and avoid potential circular dependencies.
        )2�generated_operations�altered_indexes�altered_constraintsr�
concrete_apps�old_appsr�apps�new_apps�set�old_model_keys�old_proxy_keys�old_unmanaged_keys�new_model_keys�new_proxy_keys�new_unmanaged_keysr�	get_model�_meta�managed�add�	real_apps�proxy�generate_renamed_models�_prepare_field_lists�_generate_through_model_map�generate_deleted_models�generate_created_models�generate_deleted_proxies�generate_created_proxies�generate_altered_options�generate_altered_managers�create_altered_indexes�create_altered_constraints�generate_removed_constraints�generate_removed_indexes�generate_renamed_fields�generate_removed_fields�generate_added_fields�generate_altered_fields�&generate_altered_order_with_respect_to� generate_altered_unique_together�generate_altered_index_together�generate_added_indexes�generate_added_constraints�generate_altered_db_table�_sort_migrations�_build_migration_list�_optimize_migrations�
migrations)rr r�al�mnrrrrresv

���
z%MigrationAutodetector._detect_changescs`�j�j@�_�j�j@�_�j�j@�_i�_	�fdd��jD��_
�fdd��jD��_dS)z�
        Prepare field lists and a list of the fields that used through models
        in the old state so dependencies can be made from the through model
        deletion to the field that uses it.
        cs@h|]\}}�jj|�j�||f|�fjD]}|||f�qqSr)rr�renamed_models�getrJ�r�	app_label�
model_name�
field_namer(rrr�s�����z=MigrationAutodetector._prepare_field_lists.<locals>.<setcomp>cs2h|]\}}�jj||fjD]}|||f�qqSr)rrrJr�r(rrr�s���N)rXr[�kept_model_keysrYr\�kept_proxy_keysrZr]�kept_unmanaged_keys�
through_users�old_field_keys�new_field_keysr(rr(rre�s
�
�z*MigrationAutodetector._prepare_field_listscCs�t|j�D]L\}}|j�||f|�}|jj||f}|jD]3}|j�||�j	�
|�}t|d�rPt|j
dd�rP|j
jj	jsP|j
jj	j|j
jj	jf}|||f|j|<qqdS)zThrough model map generation.rH�throughN)rGrXr�r�rrrJrTr^r_�	get_fieldr?�getattrrHr��auto_createdr�r�r�)rr�r��old_model_name�old_model_stater��	old_field�through_keyrrrrf�s

�

����z1MigrationAutodetector._generate_through_model_mapcCsH|ddkr
|dfStt|d��d�\}}||��f|dd�dfS)	zp
        Return the resolved dependency and a boolean denoting whether or not
        it was swappable.
        r�__setting__Fr3�.rENT)r�r�split�lower)�
dependency�resolved_app_label�resolved_object_namerrr�_resolve_dependency�sz)MigrationAutodetector._resolve_dependencyc	Cs\i|_tdd�|j��D��}d}|�r,t|j�D]�}g}t�}t|j|�D]�}d}t�}	|jD]v}
|
}|�|
�\}
}|
d|kr�|j�	|
dg�D]}
|�
|
|
�rWd}nqK|s\nL|rj|	�|d|df�q1|
d|jvr�|	�|
d|j|
ddjf�q1|r�|r�|�
|
d�r�|	�|�
|
d�d�q1|	�|
ddf�q1d}q1|r�|�|�|�|	�|j|d=q'|s�|�r|j|r�|r�td	tfggd
��}|dt|j�	|g��d|�}t|�|_||_||jv|_|j�|g��|�d}q||j||j|<qtdd�|j��D��}||k�r&|�sd}ntd
|j��|}|sdSdS)ag
        Chop the lists of operations up into migrations with dependencies on
        each other. Do this by going through an app's list of operations until
        one is found that has an outgoing dependency that isn't in another
        app's migration yet (hasn't been chopped off its list). Then chop off
        the operations before it into a migration and move onto the next app.
        If the loops completes without doing anything, there's a circular
        dependency (which _should_ be impossible as the operations are
        all split at this point so they can't depend and be depended on).
        cs��|]}t|�VqdSr+��len�r�xrrrr,��z>MigrationAutodetector._build_migration_list.<locals>.<genexpr>FTrr3����	__first__r)r�dependencieszauto_%icsr�r+r�r�rrrr,Gr�z)Cannot resolve operation dependencies: %rN)r~�sumrP�valuesrGrWr5�
_auto_depsr�r��check_dependencyrarL�
leaf_nodesrI�updater>rr�r�rr�initial�
setdefault�
ValueError)rr�num_ops�	chop_moder��choppedr��	operation�deps_satisfied�operation_dependencies�dep�original_dep�is_swappable_dep�other_operation�subclass�instance�new_num_opsrrrr|�sl
�$�


 
�
�z+MigrationAutodetector._build_migration_listcCs�t|j���D]=\}}dd�|D�}|D]'}|jD]!}|�|�d}|d|kr:|D]}|�||�r9||�|�q*qqt||�|j|<qdS)z{
        Reorder to make things possible. Reordering may be needed so FKs work
        nicely inside the same app.
        cSsi|]}|t��qSr)rW)r�oprrrr0Vrz:MigrationAutodetector._sort_migrations.<locals>.<dictcomp>rN)rGrPr8r�r�r�rar)rr��ops�dependency_graphr�r��op2rrrr{Os
��
�z&MigrationAutodetector._sort_migrationscCs�|j��D]\}}t||dd��D]
\}}|j�||jf�qq|j��D]}|D]
}tt|j��|_q*q&|j��D]\}}|D]}t	��
|j|�|_qAq;dS)Nr3)r~r8�zipr�rIrLr�r5rWr�optimizer)rr�r~�m1�m2�	migrationrrrr}ds����z*MigrationAutodetector._optimize_migrationscs�ddur�ddurt|tj�o|j�d��kS�ddurZ�ddurZt|tj�oA|j�d��koAt�fdd�|jD��pYt|tj�oY|j�d��koY|j�d��kS�ddur~�ddur~t|tj	�o}|j�d��ko}|j�d��kS�ddur��ddur�t|tj
�o�|j�d��kS�ddur��dd	kr�t|tj�o�|j�d��ko�|j�d��kS�ddur�dd
kr�t|tj�o�|j�d��ko�|j
p�d���d��kS�ddu�r�ddk�rt|tjtjf��o|j�d��kStd
�f��)zn
        Return True if the given operation depends on the given dependency,
        False otherwise.
        rEN�Tr3c3s �|]\}}�d|kVqdS)rENr)rr��y�r�rrr,�s�z9MigrationAutodetector.check_dependency.<locals>.<genexpr>F�alter�order_wrt_unset��foo_together_changezCan't handle dependency %r)r4r�CreateModel�
name_lowerr��anyrJ�AddField�model_name_lower�RemoveField�DeleteModel�
AlterField�AlterOrderWithRespectTo�order_with_respect_to�AlterUniqueTogether�AlterIndexTogetherr�)rr�r�rr�rr�tsX�����
���������z&MigrationAutodetector.check_dependencyFcCs@|pg|_|r|j�|g��d|�dS|j�|g��|�dS)Nr)r�rPr��insertrI)rr�r�r��	beginningrrr�
add_operation�s
z#MigrationAutodetector.add_operationcCs�zB|j�|d|d�}dd�|jD�}d|d|df}|jjs3d|vs3d|vs3tj��|��kr@d|dd|dfWSW|StyLY|Sw)	z|
        Place potential swappable models first in lists of created models (only
        real way to solve #22783).
        rr3cSsg|]}|j�qSr)�__name__)r�baserrrr)�sz=MigrationAutodetector.swappable_first_key.<locals>.<listcomp>�%s.%s�AbstractUser�AbstractBaseUser�___)	rVr^�	__bases__r_�	swappabler�AUTH_USER_MODELr��LookupError)r�itemr�
base_names�string_versionrrr�swappable_first_key�s ����z)MigrationAutodetector.swappable_first_keycCsLi|_i|_|j|j}t|�D]�\}}|jj||f}|�|j�}|j|j}|D]x\}}||kr�|j	j||f}	|�|	j�}
||
kr�|j
�|	|�r�|j�
||�j}g}|��D]
}
|
jrf|�|�|
��qY|j|tj|	j|jd�|d�||j||f<d|	j|	jf}d|j|jf|j|<|j�||f�|j�||f�nq*qdS)z�
        Find any renamed models, generate the operations for them, and remove
        the old entry from the model lists. Must be run before other
        model-level generation.
        )�old_name�new_name�r�r�N)r��renamed_models_relr[rXrGrrrOrJrr�ask_rename_modelrVr^r_�
get_fields�is_relation�extend�!_get_dependencies_for_foreign_keyr�r�RenameModelrLr�r��removera)r�added_modelsr�r��model_state�model_fields_def�removed_models�
rem_app_label�rem_model_name�rem_model_state�rem_model_fields_def�
model_optsr�rM�renamed_models_rel_keyrrrrd�sR�������z-MigrationAutodetector.generate_renamed_modelsc
s|j|jB}|j|}|j|}tt||jdd�t||jdd��}|D�]�\��|jj��f}|j	�
���j}i�d}|jD],}|j
rk|j
jrY|jrP|j
j}n	|j
jsY|�|j<t|j
dd�rk|j
jjjsk|�|j<q?|jD]}|j
jrz|�|j<t|j
dd�r�|j
jjjs�|�|j<qo|j�d�}	|j�d�}
|j�dd�}|j�dd�}|j�d	d�}
��dd
fg}|jD]Q}t|t��r	d|v�r	|�dd�\}}|�||ddf�|jj�||f�}|jj�||f�}|�r	|�r	t|j ��!|j ��"|j �}|D]}|�|||d
f�q�q�|�r|�|jj#|jj$ddf�|j%�t&j'|j�fd
d�|j �(�D�|j|j|j)d�|dd�|j*�s>q#t��(��D]%\}}|�+|�}|���ddf�|j%�t&j,�||d�t-t|��d��qD|
�r�|j%�t&j.�|
d���|
df��ddfgd���fdd�t��D�}|���ddf�|	D]}|j%�t&j/�|d�|d��q�|
D]}|j%�t&j0�|d�|d��q�|�r�|j%�t&j1�|d�|d�|�r�|j%�t&j2�|d�|d���f|j3v�r
|j4D]}|j%|j5jj#t&j6|j5jj$|j7j|j7d���ddfgd��q�q#dS)a�
        Find all new models (both managed and unmanaged) and make create
        operations for them as well as separate operations to create any
        foreign key or M2M relationships (these are optimized later, if
        possible).

        Defer any model options that refer to collections of fields that might
        be deferred (e.g. unique_together, index_together).
        T)r/�reverseNr��indexes�constraints�unique_together�index_togetherr�Fr�r3csg|]
}|d�vr|�qS)rr�r�d)�related_fieldsrrr)KszAMigrationAutodetector.generate_created_models.<locals>.<listcomp>�rLrJ�options�bases�managers)r�r�)r�rLrMr��rLr�csg|]}��|df�qS)Tr)rrL)r�r�rrr)ts
���r��index�r��
constraint�rLr�rLr)8rXrZr[r]rrGr�rrrVr^r_�local_fieldsrHr�primary_key�parent_linkrLr�r�r��local_many_to_manyr�poprr4�strr�rIrr�rWrJ�
difference�intersectionr��object_namer�rr�r8r	r`r�r�r5r��AddIndex�
AddConstraintr�r�rY�related_objects�
related_modelr�rM)r�old_keysr��added_unmanaged_models�all_added_modelsr�r��primary_key_relrMr�rrrr�r�r��base_app_label�	base_name�old_base_model_state�new_base_model_state�removed_base_fields�removed_base_fieldrL�related_dependenciesrr�related_objectr)r�r�rrrh�s,


�



�
�


�
�

������
�

�
�

����
��
�����

�
����z-MigrationAutodetector.generate_created_modelsc	
Cs�|j|j}t|�D]O\}}|jj||f}|j�d�sJ�||ddfg}|jD]}t|t	�rDd|vrD|�
dd�\}}|�||ddf�q(|j|t
j|jg|j|j|jd�|d�q
dS)	z�
        Make CreateModel statements for proxy models. Use the same statements
        as that way there's less code duplication, but for proxy models it's
        safe to skip all the pointless field stuff and chuck out an operation.
        rcNFr�r3Trr�)r\rYrGrrrr�rr4rr�rIr�rr�rLr	)	r�addedr�r�r�r�r�r"r#rrrrj�s.
�
����z.MigrationAutodetector.generate_created_proxiesc	Cs8|j|jB}|j|}|j|}tt|�t|��}|D]�\}}|jj||f}|j�	||�}i}	|j
jD] }
|
jrT|
jj
rB|
|	|
j<t|
jdd�rT|
jjj
jsT|
|	|
j<q4|j
jD]}
|
jj
rd|
|	|
j<t|
jdd�rv|
jjj
jsv|
|	|
j<qY|j�dd�}|j�dd�}|r�|�|tj|dd��|r�|�|tj|dd��t|	�D]
}
|�|tj||
d��q�g}|j
jD]%}|jj
j}|jj
j}|jj}|�|||df�|j s�|�|||d	f�q�t|	�D]}
|�|||
df�q�|j!�"||j#f�}|�r|�|d
|d|ddf�|j|tj$|jd
�t%t&|��d�qdS)a�
        Find all deleted models (managed and unmanaged) and make delete
        operations for them as well as separate operations to delete any
        foreign key or M2M relationships (these are optimized later, if
        possible).

        Also bring forward removal of any model options that refer to
        collections of fields - the inverse of generate_created_models().
        r�Nrrrr�r�rLFr�rr3rE�rLr�)'r[r]rXrZrrGrrrTr^r_rrHrrLr�r�r�rrrr�rr�r�r�rrr�rrMrI�many_to_manyr�r�r�r�r5rW)r�new_keys�deleted_models�deleted_unmanaged_models�all_deleted_modelsr�r�r�rrrMrrrLr�r)�related_object_app_labelrr��through_userrrrrg�s�




�
�

�������

��
��z-MigrationAutodetector.generate_deleted_modelscCsX|j|j}t|�D]\}}|jj||f}|j�d�sJ�|�|tj	|j
d��q
dS)z*Make DeleteModel options for proxy models.rcr,N)rYr\rGrrrr�r�rr�rL)r�deletedr�r�r�rrrri%s���z.MigrationAutodetector.generate_deleted_proxiesc
Cs�i|_t|j|j�D]�\}}}|j�||f|�}|jj||f}|j�	||�j
�|�}|�|�}t|j|j�D]�\}}	}
||kr�|	|kr�|j
|
}|�|�}|jrq|jjrqd|dvrq|dd}
|
|jvrq|j|
|dd<|�|
�|��d}||ks�|dd�|dd�kr�t|d|d�|dkr�|j�||
||�r�|�|tj||
|d��|j�||	|
f�|j�|||f�|
|j|||f<nq9qdS)zWork out renamed fields.rFrEr3r)�	db_column)r�r�r�N)�renamed_fieldsrGr�r�r�r�rrrVr^r_r�r%rJrHrr��set_attributes_from_name�get_attname_columnr7r�
ask_renamer�r�RenameFieldr�ra)rr�r�r�r�r�rM�	field_decr�r��rem_field_namer��
old_field_dec�
old_rel_to�
old_db_columnrrrrq2sD




����z-MigrationAutodetector.generate_renamed_fieldscC�.t|j|j�D]\}}}|�|||�qdS)zMake AddField operations.N)rGr�r��_generate_added_field�rr�r�r�rrrrsX��z+MigrationAutodetector.generate_added_fieldscCs�|j�||�j�|�}g}|jr|jjr|�|�|��tj	tj
tjf}|jp;|�
�p;|jp;|jo3|jp;t||�o;|j}|s[|��}t||�rS|jrS|j�||�|_n|j�||�|_|j|tj||||d�|d�dS)N�r�rLrM�preserve_defaultr�)rVr^r_r�rHrr�r�r�	DateField�
DateTimeField�	TimeField�null�has_defaultr-�blank�empty_strings_allowedr4�auto_now�clone�auto_now_addr�ask_auto_now_add_addition�default�ask_not_null_additionr�rr�)rr�r�r�rMr��time_fieldsrErrrrA]s2
���
�z+MigrationAutodetector._generate_added_fieldcCr@)zMake RemoveField operations.N)rGr�r��_generate_removed_fieldrBrrrrr|rCz-MigrationAutodetector.generate_removed_fieldscCs2|j|tj||d�|||df|||dfgd�dS)Nr+r�r�r�)r�rr�rBrrrrT�s�

�
�z-MigrationAutodetector._generate_removed_fieldc	sxt�j�j@�D�]0\}}}�j�||f|�}�j�|||f|�}�j�||�j�	|�}�j
�||�j�	|�}g}t|d�r�t|j
dd�r�|j
jjj|j
jjjf���jvr\|j
j|j
_t|j
dd�}	|	r{�|	f}
|
�jvr{|j
j|j
_|j
j|j
_t|dd�}|r�||f�t��fdd�|D��|_t��fdd�|jD��|_|���|��t|d�r�t|j
d	d�r�|j
jjj|j
jjjf���jvr�|j
j|j
_��|�}��|�}
||
k�r9|jo�|j}|jo�|j}|s�|�r+d
}|j�r|j�s|���s|j�s|��}�j�||�}|tj u�r||_!d}n|}�j"|t#j$||||d�|d
�q��%|||���&|||�qdS)zp
        Make AlterField operations, or possibly RemovedField/AddField if alter
        isn's possible.
        rHrNr��from_fieldsc� g|]}�j��|f|��qSr�r6r�)r�
from_field)�from_rename_keyrrrr)����zAMigrationAutodetector.generate_altered_fields.<locals>.<listcomp>crVrrW)r�to_field)�
rename_keyrrrr)�rZr�TFrDr�)'rGr�r�r�r�r6rTr^r_r�rVr?r�rHrr�r�r�r6rU�	to_fieldsr�r�r�r%r-rIrJrNr�ask_not_null_alterationr�NOT_PROVIDEDrQr�rr�rTrA)rr�r�r�r��old_field_namer��	new_fieldr��remote_field_name�to_field_rename_keyrUr=�
new_field_dec�both_m2m�neither_m2mrErM�new_defaultr)rYr\rrrt�s�

�



�
�

�




������z-MigrationAutodetector.generate_altered_fieldsc	�tjj}t|j�D]F\}}|j�||f|�}|jj||f}|j	j||f}|j
|�|j
|��fdd��D�}�fdd��D�}|j�||f||d�i�q	dS)Nc�g|]}|�vr|�qSrr�r�idx)�old_indexesrrr)��z@MigrationAutodetector.create_altered_indexes.<locals>.<listcomp>crirrrj)�new_indexesrrr)�rm)�
added_indexes�removed_indexes)
rr�option_namerGr�r�r�rrrrrQr�)	rrqr�r�r�r��new_model_state�add_idx�rem_idxr)rnrlrrm��

���z,MigrationAutodetector.create_altered_indexesc	C�@|j��D]\\}}}|dD]
}|�|tj||d��qqdS)Nror)rQr8r�rr�rr�r��alt_indexesrrrrrx������z,MigrationAutodetector.generate_added_indexesc	C�B|j��D]\\}}}|dD]}|�|tj||jd��qqdS)Nrpr+)rQr8r�r�RemoveIndexrLrwrrrrp�����z.MigrationAutodetector.generate_removed_indexesc	rh)Ncrirr�r�c)�old_constraintsrrr)rmzDMigrationAutodetector.create_altered_constraints.<locals>.<listcomp>crirrr})�new_constraintsrrr)rm)�added_constraints�removed_constraints)
rrrqrGr�r�r�rrrrrRr�)	rrqr�r�r�r�rr�add_constraints�rem_constraintsr)r�rrrnruz0MigrationAutodetector.create_altered_constraintsc	Crv)Nr�r
)rRr8r�rr�rr�r��alt_constraintsrrrrryryz0MigrationAutodetector.generate_added_constraintsc	Crz)Nr�r+)rRr8r�r�RemoveConstraintrLr�rrrro)r|z2MigrationAutodetector.generate_removed_constraintscCs�t|dd�}|durd}|}n|jjjj}|jjjj}||ddfg}t|jdd�r@|jjjjs@|�|jjjj|jjjjddf�|S)N�swappable_settingr�Tr�)	r�rHrr_r�rr�r�rI)rrMr��
dep_app_label�dep_object_namer�rrrr�4s

�z7MigrationAutodetector._get_dependencies_for_foreign_keycs|j}t�j�D]}\���j���f��}�jj�|f}�jj��f}|j�|�}|r8���fdd�|D�nt	�}|j�|�}|rGt	|�nt	�}||kr�g}|D]!}	|	D]}
�j
����j�
|
�}|jrr|jjrr|���|��qVqR�j�|dd�i||i��|d�qdS)Ncs&h|]}t���fdd�|D���qS)c3s$�|]
}�j���|f|�VqdSr+rW)r�n�r�r�rrrr,Qs
��
�zQMigrationAutodetector._generate_altered_foo_together.<locals>.<setcomp>.<genexpr>)r6)r�uniquer�rrrPs���zGMigrationAutodetector._generate_altered_foo_together.<locals>.<setcomp>rLr�r)rqrGr�r�r�rrrrrWrVr^r_r�rHrr�r�r�)rr�rqr�r�rr�	old_value�	new_valuer��
foo_togethersr�rMrr�r�_generate_altered_foo_togetherGsD����������z4MigrationAutodetector._generate_altered_foo_togethercC�|�tj�dSr+)r�rr�r(rrrrvl�z6MigrationAutodetector.generate_altered_unique_togethercCr�r+)r�rr�r(rrrrwor�z5MigrationAutodetector.generate_altered_index_togetherc	Cs�|j�|j|j�}t|�D]8\}}|j�||f|�}|jj||f}|j	j||f}|j
�d�}|j
�d�}||krE|�|tj
||d��q
dS)N�db_table)rL�table)r��unionr�r�rGr�r�rrrrr�r�AlterModelTable)	r�models_to_checkr�r�r�r�rr�old_db_table_name�new_db_table_namerrrrzrs"����z/MigrationAutodetector.generate_altered_db_tablec	Cs�|j�|j|j|j|j@|j|j@�}t|�D]@\}}|j	�
||f|�}|jj||f}|j
j||f}dd�|j��D�}dd�|j��D�}||krW|�|tj||d��qdS)z�
        Work out if any non-schema-affecting options have changed and make an
        operation to represent them in state changes (in case Python code in
        migrations needs them).
        cS� i|]\}}|tjvr||�qSr�r�ALTER_OPTION_KEYSr.rrrr0��

�zBMigrationAutodetector.generate_altered_options.<locals>.<dictcomp>cSr�rr�r.rrrr0�r�)rLrN)r�r�r�r�rZr[rXr]rGr�r�rrrrr8r�rr)	rr�r�r�r�r�rr�old_options�new_optionsrrrrk�s4

�	������z.MigrationAutodetector.generate_altered_optionscCs�t|j�D]N\}}|j�||f|�}|jj||f}|jj||f}|j�d�|j�d�krSg}|j�d�rB|�|||jddf�|j	|t
j||j�d�d�|d�qdS)Nr�Tr
r�)rGr�r�r�rrrrrIr�rr�)rr�r�r�r�rrr�rrrru�s2

��
����z<MigrationAutodetector.generate_altered_order_with_respect_tocCsnt|j�D]/\}}|j�||f|�}|jj||f}|jj||f}|j|jkr4|�|t	j
||jd��qdS)N)rLr	)rGr�r�r�rrrr	r�r�AlterModelManagers)rr�r�r�r�rrrrrrl�s����z/MigrationAutodetector.generate_altered_managerscst|��}i�t|���D]�\}}|sqd}|D]}|d|kr#|}nq|dur@|j�|�s@|D]}	|df�||	jf<q0||=q|durGd}
n|�|d�pOdd}
t|�D]I\}}	|dkrf|rf|	j�	|�d|
g}|rs|�	|�n|dkr|s|�	d�n|�	|	�
�dd��d�|�}
||
f�||	jf<|
d7}
|
|	_qVq|��D]}|D]
}	�fd	d
�|	jD�|	_q�q�|S)z�
        Take a result from changes() and a MigrationGraph, and fix the names
        and dependencies of the changes so they extend the graph from the leaf
        nodes for each app.
        Nrr�r3z%04ir��d�_csg|]}��||��qSr�r�r��name_maprrr)�rmz;MigrationAutodetector.arrange_for_graph.<locals>.<listcomp>)
r�r5r8r�ask_initialrL�parse_number�	enumerater�rI�suggest_name�joinr�)rr"rr!�leavesr�r~�app_leaf�leafr��next_number�i�new_name_partsr�rr�rr�sL�

��z'MigrationAutodetector.arrange_for_graphc
s�i�|��D]\}}|D]}|jD]\}}��|t���|�qqqt|�}d}	|	|kr@t|�}	|j�fdd�|D��|	|ks,t|�D]	}||vrM||=qD|S)a1
        Take changes from arrange_for_graph() and set of app labels, and return
        a modified set of changes which trims out as many migrations that are
        not in app_labels as possible. Note that some other migrations may
        still be present as they may be required dependencies.
        Ncsg|]}��|d��qS)rr�)rr���app_dependenciesrrr)rmz7MigrationAutodetector._trim_to_apps.<locals>.<listcomp>)r8r�r�rWrar�r5)
rr"�
app_labelsr�r~r�r�rL�
required_apps�old_required_appsrr�rrs$����z#MigrationAutodetector._trim_to_appscCs t�d|�}|rt|d�SdS)z�
        Given a migration name, try to extract a number from the beginning of
        it. If no number is found, return None.
        z^\d+rN)�re�match�int)�clsrLr�rrrr�sz"MigrationAutodetector.parse_numberr+)NNN)NN)NF)0r��
__module__�__qualname__�__doc__rr"r%rOrrerf�staticmethodr�r|r{r}r�r�r�rdrhrjrgrirqrsrArrrTrtrmrxrprnryror�r�rvrwrzrkrurlrr�classmethodr�rrrrr
s^

(
a


W
?./!Y
&S%$
2r
)r9r��	itertoolsr�django.confr�	django.dbr�django.db.migrationsr�django.db.migrations.migrationr�&django.db.migrations.operations.modelsr�django.db.migrations.optimizerr�django.db.migrations.questionerr	�django.db.migrations.utilsr
r�django.utils.topological_sortrr
rrrr�<module>s

https://t.me/RX1948 - 2025