/usr/local/lib/python3.9/site-packages/django/core/management/commands/__pycache__
a Ӱ�h�S � @ s� d dl Z d dlZd dlmZ d dlmZ d dlmZmZm Z d dl mZmZ d dl mZmZmZ d dlmZ d dlmZ d d lmZ d d lmZmZ d dlmZ d dlmZ G d d� de�ZdS )� N)� import_module)�apps)�BaseCommand�CommandError�no_translations)�emit_post_migrate_signal�emit_pre_migrate_signal)�DEFAULT_DB_ALIAS�connections�router)�MigrationAutodetector)�MigrationExecutor)�AmbiguityError)� ModelState�ProjectState)�module_has_submodule)� Truncatorc @ sF e Zd ZdZg Zdd� Zedd� �Zddd �Zd d� Z e dd � �ZdS )�CommandzMUpdates database schema. Manages both apps with migrations and those without.c C s� |j dddd� |j dddd� |j d dd d� |j ddd ddd� |j dtdd� |j dddd� |j dddd� |j dddd� |j dddd� |j ddddd� |j ddd d!d� d S )"Nz --skip-checks� store_truezSkip system checks.)�action�help� app_label�?z5App label of an application to synchronize the state.)�nargsr �migration_namezpDatabase state will be brought to the state after that migration. Use the name "zero" to unapply all migrations.z --noinputz --no-input�store_false�interactivez:Tells Django to NOT prompt the user for input of any kind.)r �destr z --databasezHNominates a database to synchronize. Defaults to the "default" database.)�defaultr z--fakez5Mark migrations as run without actually running them.z--fake-initialz�Detect if tables already exist and fake-apply initial migrations if so. Make sure that the current database schema matches your initial migration before using this flag. Django will only check for an existing table name.z--planz=Shows a list of the migration actions that will be performed.z--run-syncdbz+Creates tables for apps without migrations.z--check�check_unappliedzbExits with a non-zero status if unapplied migrations exist and does not actually apply migrations.z--prune�prunez?Delete nonexistent migrations from the django_migrations table.)�add_argumentr )�self�parser� r$ �Q/usr/local/lib/python3.9/site-packages/django/core/management/commands/migrate.py� add_arguments sv ������� ��� �zCommand.add_argumentsc % s� |d }|d s| j |gd� |d | _|d | _t�� D ]}t|jd�r:td|j� q:t | }|� � t|| j�}|j �|� |j �� }|r�d�d d � |�� D ��}td| ��|d } d } |d �rN|d � zt�� � W n2 t�y } ztt|���W Y d }~n d }~0 0 | �r4� |j jv �rNtd� ��n� |j jv�rNtd� ��|d �r$|d �r$|d }|dk�r�� d fg} n�z|j �� |�}W nF t�y� td|� f ��Y n$ t�y� td|� f ��Y n0 � |jf}||j jjv�r||j jv �r|j j| }|jd }|g} d} n2|d �rJ� fdd�|j j�� D �} n|j j�� } |d �r�|d �srtd��| jdk�r�| j� d| j!j"� t#|j j$�t#|j j%� ��fdd�|j j�� D �}|�r| j� | j!�&d�� |D ]&}|\}}| j� d|� d |� �� �q�| j� | j!�&d!�� n�t'� fd"d ��D �����r��D ]l}|\}}| jdk�rz| jj | j!�(d#|� d |� ��d$d%� |j)�*||� | jdk�r>| j� | j!�+d&�� �q>n| jdk�r�| j� d'� |�,| �}|d( �r�| j� d)| j!j(� |�s | j� d*� n||D ]b\}}| j� t|�| j!j"� |j-D ]:}| �.||�\}}|�rJ| j!j/nd }| j� d| |� �q(�q|d+ �r|t0�1d,� d S |d+ �r�|�r�t0�1d,� d S |d �r�d S |d �o�|j j2} | jd,k�r�| j� | j!�"d-�� | �r.|d �r| j� | j!�(d.� �� n&| j� | j!�(d/�d0�t'|j j2�� � | �rh| j� | j!�(d1�d0�t'd2d3� | D ����p`d4 � nh| d d, d u �r�| j� | j!�(d5�t| d d � � n0| j� | j!�(d6�d7| d d, | d d f � |j3d d8�}|j}t4| j| j|j5| j||d9� | �rN| jd,k�r$| j� | j!�"d:�� |d �r>| �6|� g� n| �6||j j2� | jd,k�rn| j� | j!�"d;�� |�s| jd,k�r�| j� d<� t7|j �8� t9�:t��}|j;|j jd=�}|�r�| j� | j!�&d>d0�d?d � t'|�D �� �� | j� | j!�&d@�� d}d}n|dA }|dB }|j<| ||�=� ||dC�} | �>� | j}!|!�?� �B g }"|!j@D ]&}#|#jA|#jBf}$|"�C|$� |!jD|$� �qLW d � n1 �s�0 Y |!�EdDd� |"D �� tF| j| j|j5| j|!|d9� d S )EN�databaseZskip_checks)Z databases� verbosityr Z managementz.managementz; c s s$ | ]\}}d d� |�|f V qdS )z%s in %s�, N)�join)�.0�app�namesr$ r$ r% � <genexpr>~ s z!Command.handle.<locals>.<genexpr>z�Conflicting migrations detected; multiple leaf nodes in the migration graph: (%s). To fix them run 'python manage.py makemigrations --merge'� run_syncdbTr z8Can't use run_syncdb with app '%s' as it has migrations.z"App '%s' does not have migrations.r �zerozJMore than one migration matches '%s' in app '%s'. Please be more specific.z4Cannot find a migration matching '%s' from app '%s'.���Fc s g | ]}|d � kr|�qS )r r$ )r+ �key�r r$ r% � <listcomp>� s z"Command.handle.<locals>.<listcomp>r z7Migrations can be pruned only when an app is specified.r zPruning migrations:c s, g | ]$\}}t � fd d�|jD ��r|�qS )c 3 s | ]}|� v V qd S �Nr$ )r+ Zreplaced��to_pruner$ r% r. � � z,Command.handle.<locals>.<listcomp>.<genexpr>)�any�replaces)r+ Z migration_keyZ migration_objr6 r$ r% r4 � s �z� Cannot use --prune because the following squashed migrations have their 'replaces' attributes and may not be recorded as applied:z �.z| Re-run 'manage.py migrate' if they are not marked as applied, and remove 'replaces' attributes in their Migration classes.c 3 s | ]}|d � kr|V qdS )r Nr$ )r+ � migrationr3 r$ r% r. � s z Pruning � ��ending� OKz No migrations to prune.�planzPlanned operations:z" No planned migration operations.r � zOperations to perform:z Synchronize unmigrated app: %sz Synchronize unmigrated apps: r) z Apply all migrations: c S s h | ]\}}|�qS r$ r$ )r+ �a�nr$ r$ r% � <setcomp> r8 z!Command.handle.<locals>.<setcomp>z(none)z Unapply all migrations: z Target specific migration: z%s, from %s)Zwith_applied_migrations)�stdoutr rA z&Synchronizing apps without migrations:zRunning migrations:z No migrations to apply.)�graphzl Your models in app(s): %s have changes that are not yet reflected in a migration, and so won't be applied.c s s | ]}t |�V qd S r5 )�repr)r+ r, r$ r$ r% r. U r8 zk Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.�fake�fake_initial)rA �staterI rJ c S s g | ]}t �tj|� ��qS r$ )r Z from_modelr Z get_model)r+ �modelr$ r$ r% r4 z r8 )G�checkr( r r �get_app_configsr �moduler �namer Zprepare_databaser �migration_progress_callback�loaderZcheck_consistent_historyZdetect_conflictsr* �itemsr Zget_app_config�LookupError�strZ migrated_appsZget_migration_by_prefixr �KeyErrorrG �nodesZreplacementsr: Z leaf_nodesrF �write�styleZMIGRATE_HEADING�setZapplied_migrationsZdisk_migrationsZNOTICE�sortedZ MIGRATE_LABELZrecorderZrecord_unapplied�SUCCESSZmigration_plan� operations�describe_operation�WARNING�sys�exitZunmigrated_appsZ_create_project_stater �alias� sync_appsr Z project_stater Z from_apps�changesZmigrate�cloneZclear_delayed_apps_cacheZbulk_updateZreal_modelsr Z name_lower�appendZunregister_modelZrender_multipler )%r"