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

3�a�?�@s~ddlZddlZddlmZmZddlmZddlmZddl	m
Z
ddlmZddl
mZmZmZmZd	ZGd
d�d�ZdS)�N)�
import_module�reload)�apps)�settings)�MigrationGraph)�MigrationRecorder�)�AmbiguityError�BadMigrationError�InconsistentMigrationHistory�NodeNotFoundError�
migrationsc@s�eZdZdZ		ddd�Zedd��Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zd dd�Zdd�ZdS)!�MigrationLoaderal
    Load migration files from disk and their status from the database.

    Migration files are expected to live in the "migrations" directory of
    an app. Their names are entirely unimportant from a code perspective,
    but will probably follow the 1234_name.py convention.

    On initialization, this class will scan those directories, and open and
    read the Python files, looking for a class called Migration, which should
    inherit from django.db.migrations.Migration. See
    django.db.migrations.migration for what that looks like.

    Some migrations will be marked as "replacing" another set of migrations.
    These are loaded into a separate set of migrations away from the main ones.
    If all the migrations they replace are either unapplied or missing from
    disk, then they are injected into the main set, replacing the named migrations.
    Any dependency pointers to the replaced migrations are re-pointed to the
    new migration.

    This does mean that this class MUST also talk to the database as well as
    to disk, but this is probably fine. We're already not just operating
    in memory.
    TFcCs2||_d|_d|_||_||_|r|��dSdS�N)�
connection�disk_migrations�applied_migrations�ignore_no_migrations�replace_migrations�build_graph)�selfr�loadrr�r�=/usr/lib/python3/dist-packages/django/db/migrations/loader.py�__init__+s�zMigrationLoader.__init__cCs4|tjvrtj|dfSt�|�j}d|tfdfS)z�
        Return the path to the migrations module for the specified app_label
        and a boolean indicating if the module is specified in
        settings.MIGRATION_MODULE.
        T�%s.%sF)r�MIGRATION_MODULESr�get_app_config�name�MIGRATIONS_MODULE_NAME)�cls�	app_label�app_package_namerrr�migrations_module7s
z!MigrationLoader.migrations_modulecCs�i|_t�|_t�|_t��D]�}|�|j�\}}|dur%|j�|j�q|t	j
v}zt|�}Wn)tyY}z|r=|j
sG|sTt|j�d�vrT|j�|j�WYd}~q�d}~wwt|d�sg|j�|j�qt|dd�dur}t|jt�s}|j�|j�q|r�t|�|j�|j�dd�t�|j�D�}|D]D}d||f}	zt|	�}
Wnty�}zdt|�vr�td	|	�|��d}~wwt|
d
�s�td||jf��|
�||j�|j|j|f<q�qdS)z6Load the migrations from all INSTALLED_APPS from disk.N�.�__path__�__file__cSs&h|]\}}}|s|ddvr|�qS)rz_~r)�.0�_r�is_pkgrrr�	<setcomp>ls��z,MigrationLoader.load_disk.<locals>.<setcomp>rzbad magic numberz9Couldn't import %r as it appears to be a stale .pyc file.�	Migrationz-Migration %s in app %s has no Migration class)r�set�unmigrated_apps�
migrated_appsr�get_app_configsr#�label�add�sys�modulesr�ModuleNotFoundErrorrrr�split�hasattr�getattr�
isinstancer%�listr�pkgutil�iter_modules�ImportError�strr
r+)r�
app_config�module_name�explicit�
was_loaded�module�e�migration_names�migration_name�migration_path�migration_modulerrr�	load_diskDs�
�����


�
������
����zMigrationLoader.load_diskcCs|jj||fS)z6Return the named migration or raise NodeNotFoundError.��graph�nodes)rr!�name_prefixrrr�
get_migration�szMigrationLoader.get_migrationcCsrg}|jD]\}}||kr|�|�r|�||f�qt|�dkr(td||f��|s2td||f��|j|dS)zZ
        Return the migration(s) which match the given app label and name_prefix.
        rz>There is more than one migration for '%s' with the prefix '%s'z1There no migrations for '%s' with the prefix '%s'r)r�
startswith�append�lenr	�KeyError)rr!rL�results�migration_app_labelrErrr�get_migration_by_prefix�s�
�z'MigrationLoader.get_migration_by_prefixcCs�|ddkr|ddks||jvr|S|d|krdS|d|jvr$dS|d|jvr]z|ddkr=|j�|d�dWS|j�|d�dWSty\|jrTYdStd|d��wtd|d��)Nr�	__first__�
__latest__rz(Dependency on app with no migrations: %szDependency on unknown app: %s)rJr-r.�
root_nodes�
leaf_nodes�
IndexErrorr�
ValueError)r�key�current_apprrr�	check_key�s""�zMigrationLoader.check_keycCs@|jD]}|d|dkr|ddkr|jj|||dd�qdS)z�
        Internal dependencies need to be added first to ensure `__first__`
        dependencies find the correct root node.
        rrrUT��skip_validationN)�dependenciesrJ�add_dependency)rr[�	migration�parentrrr�add_internal_dependencies�s

��z)MigrationLoader.add_internal_dependenciescCs�|jD]!}|d|dkrq|�||d�}|dur$|jj|||dd�q|jD]}|�||d�}|dur@|jj|||dd�q(dS)NrTr^)r`r]rJra�
run_before)rr[rbrc�childrrr�add_external_dependencies�s
�
��z)MigrationLoader.add_external_dependenciesc
s����jdur
i�_n
t�j�}|���_t��_i�_�j��D]\}}�j�	||�|j
r6|�j|<q#�j��D]
\}}��||�q<�j��D]
\}}��||�qL�j
r��j��D]8\}}�fdd�|j
D�}t|�rw|�j|<n�j�|d�t|�s�t|�s��j�||j
�q_�j�||j
�q_z�j��Wnbt�y}zUi}�j��D]\}}|j
D]}|�|t���|�q�q�|j|vr�|�|jt��}t�fdd�|D��}	|	s�d�dd�|D��}
td�|j|jd	|jd
|
�|j�|��d}~ww�j��dS)z�
        Build a migration dependency graph using both the disk and database.
        You'll need to rebuild the graph if you apply migrations. This isn't
        usually a problem as generally migration stuff runs in a one-shot process.
        Ncsg|]}|�jv�qSr)r)r'�target�rrr�
<listcomp>�sz/MigrationLoader.build_graph.<locals>.<listcomp>c3s�|]	}|�jjvVqdSrrI)r'�	candidaterirr�	<genexpr>s�z.MigrationLoader.build_graph.<locals>.<genexpr>z, css�|]}d|VqdS)rNr)r'�crrrrl��z�Migration {0} depends on nonexistent node ('{1}', '{2}'). Django tried to replace migration {1}.{2} with any of [{3}] but wasn't able to because some of the replaced migrations are already applied.rr)rHrrrrrJ�replacementsr�items�add_node�replacesrdrgr�all�pop�any�remove_replaced_nodes�remove_replacement_node�validate_consistencyr�
setdefaultr,r1�node�get�join�format�origin�ensure_not_cyclic)r�recorderr[rb�applied_statuses�exc�reverse_replacements�replaced�
candidates�is_replaced�triesrrirr�sf



�
�
���	��zMigrationLoader.build_graphc
s�t|�}|����D]@}||jjvrq
|jj|jD]/}|�vrI||jvr5t�fdd�|j|jD��r5qt	d�
|d|d|d|d|j���qq
dS)zs
        Raise InconsistentMigrationHistory if any applied migrations have
        unapplied dependencies.
        c3s�|]}|�vVqdSrr)r'�m��appliedrrrl0rnz;MigrationLoader.check_consistent_history.<locals>.<genexpr>zHMigration {}.{} is applied before its dependency {}.{} on database '{}'.rrN)rrrJrK�node_map�parentsrorsrrrr}�alias)rrr�rbrcrr�r�check_consistent_history s(
�����z(MigrationLoader.check_consistent_historycsVi�t�}|j��D]\}}|�vr|�|���|t���|�q
�fdd�|D�S)z�
        Look through the loaded graph and detect any conflicts - apps
        with more than one leaf migration. Return a dict of the app labels
        that conflict with the migration names that conflict.
        csi|]	}|t�|��qSr)�sorted)r'r!��	seen_appsrr�
<dictcomp>Fsz4MigrationLoader.detect_conflicts.<locals>.<dictcomp>)r,rJrXr1ry)r�conflicting_appsr!rErr�r�detect_conflicts:s
z MigrationLoader.detect_conflictsNcCs|jj||t|j�d�S)z�
        Return a ProjectState object representing the most recent state
        that the loaded migrations represent.

        See graph.make_state() for the meaning of "nodes" and "at_end".
        )rK�at_end�	real_apps)rJ�
make_stater9r-)rrKr�rrr�
project_stateHszMigrationLoader.project_statec	Cs�g}d}|D]E\}}|jjd|jd��*}|dur#|j|j|jfdd�}|s.|j||dd�}n|j||dd�}Wd�n1s@wY|�|j	�q|S)z�
        Take a migration plan and return a list of collected SQL statements
        that represent the best-efforts version of that plan.
        NT)�collect_sql�atomicF)r�)r�)
r�
schema_editorr�r�r!r�apply�unapply�extend�
collected_sql)r�plan�
statements�staterb�	backwardsr�rrrr�Qs��zMigrationLoader.collect_sql)TFT)NT)�__name__�
__module__�__qualname__�__doc__r�classmethodr#rHrMrTr]rdrgrr�r�r�r�rrrrrs$
�
B

Q
	r)r:r2�	importlibrr�django.appsr�django.confr�django.db.migrations.graphr�django.db.migrations.recorderr�
exceptionsr	r
rrrrrrrr�<module>s

https://t.me/RX1948 - 2025