3
g#                 @   sZ   d dl mZ d dlmZ d dlmZ ddlmZ G dd dZG dd	 d	e	Z
d
d ZdS )    )
operations)get_migration_name_timestamp)atomic   )IrreversibleErrorc               @   sv   e Zd ZdZg Zg Zg Zg ZdZdZ	dd Z
dd Zdd	 Zd
d Zdd ZdddZdddZdddZdd ZdS )	Migrationa  
    The base class for all migrations.

    Migration files will import this from django.db.migrations.Migration
    and subclass it as a class called Migration. It will have one or more
    of the following attributes:

     - operations: A list of Operation instances, probably from django.db.migrations.operations
     - dependencies: A list of tuples of (app_path, migration_name)
     - run_before: A list of tuples of (app_path, migration_name)
     - replaces: A list of migration_names

    Note that all migrations come out of migrations and into the Loader or
    Graph as instances, having been initialized with their app label and name.
    NTc             C   sH   || _ || _t| jj| _t| jj| _t| jj| _t| jj| _d S )N)name	app_labellist	__class__r   dependencies
run_beforereplaces)selfr   r	    r   \/var/www/tester-filtro-web/env/lib/python3.6/site-packages/django/db/migrations/migration.py__init__5   s    zMigration.__init__c             C   s"   t |to | j|jko | j|jkS )N)
isinstancer   r   r	   )r   otherr   r   r   __eq__>   s    
zMigration.__eq__c             C   s   d| j | jf S )Nz<Migration %s.%s>)r	   r   )r   r   r   r   __repr__E   s    zMigration.__repr__c             C   s   d| j | jf S )Nz%s.%s)r	   r   )r   r   r   r   __str__H   s    zMigration.__str__c             C   s   t d| j| jf S )Nz%s.%s)hashr	   r   )r   r   r   r   __hash__K   s    zMigration.__hash__c             C   s2   |}|r|j  }x| jD ]}|j| j| qW |S )z
        Take a ProjectState and return a new one with the migration's
        operations applied to it. Preserve the original object state by
        default and return a mutated state from a copy.
        )cloner   state_forwardsr	   )r   project_stateZpreserve	new_state	operationr   r   r   mutate_stateN   s    zMigration.mutate_stateFc             C   s   x| j D ]}|rV|jjd |js.|jjd |jjd|j   |jjd |jsVq|j }|j| j| |jp| jo|jdk	}|j	 r|rt|j
j |j| j||| W dQ R X q|j| j||| qW |S )a  
        Take a project_state representing all migrations prior to this one
        and a schema_editor for a live database and apply the migration
        in a forwards order.

        Return the resulting project state for efficient reuse by following
        Migrations.
        z--zB-- MIGRATION NOW PERFORMS OPERATION THAT CANNOT BE WRITTEN AS SQL:z-- %sFN)r   collected_sqlappendreduces_to_sqldescriber   r   r	   r   atomic_migration
connectionaliasZdatabase_forwards)r   r   schema_editorcollect_sqlr   	old_stateatomic_operationr   r   r   apply\   s$    	zMigration.applyc             C   s"  g }|}xT| j D ]J}|js*td|| f |j }|j }|j| j| |jd|||f qW x|D ]\}}}	|r|jjd |j	s|jjd |jjd|j
   |jjd |j	sqd|jp| jo|jdk	}
|j o|
rt|jj |j| j||	| W dQ R X qd|j| j||	| qdW |S )a  
        Take a project_state representing all migrations prior to this one
        and a schema_editor for a live database and apply the migration
        in a reverse order.

        The backwards migration process consists of two phases:

        1. The intermediate states from right before the first until right
           after the last operation inside this migration are preserved.
        2. The operations are applied in reverse order using the states
           recorded in step 1.
        z$Operation %s in %s is not reversibler   z--zB-- MIGRATION NOW PERFORMS OPERATION THAT CANNOT BE WRITTEN AS SQL:z-- %sFN)r   Z
reversibler   r   r   r	   insertr    r!   r"   r#   r   r$   r%   r&   Zdatabase_backwards)r   r   r'   r(   Zto_runr   r   r)   Zto_stateZ
from_stater*   r   r   r   unapply   s2    zMigration.unapplyc             C   s|   d}t | jdkr | jd j}n<t | jdkr\tdd | jD r\djtdd | jD }|dkrx| jrndnd	t  }|S )
z
        Suggest a name for the operations this migration might represent. Names
        are not guaranteed to be unique, but put some effort into the fallback
        name to avoid VCS conflicts if possible.
        Nr   r   c             s   s   | ]}t |tjV  qd S )N)r   r   ZCreateModel).0or   r   r   	<genexpr>   s    z)Migration.suggest_name.<locals>.<genexpr>_c             s   s   | ]}|j V  qd S )N)migration_name_fragment)r.   r/   r   r   r   r0      s    initialzauto_%s)lenr   r2   alljoinsortedr3   r   )r   r   r   r   r   suggest_name   s    zMigration.suggest_name)T)F)F)__name__
__module____qualname____doc__r   r   r   r   r3   r   r   r   r   r   r   r   r+   r-   r8   r   r   r   r   r      s    	

%
3r   c               @   s   e Zd ZdZdd ZdS )SwappableTuplez
    Subclass of tuple so Django can tell this was originally a swappable
    dependency when it reads the migration file.
    c             C   s   t j| |}||_|S )N)tuple__new__setting)clsvaluer@   r   r   r   r   r?      s    zSwappableTuple.__new__N)r9   r:   r;   r<   r?   r   r   r   r   r=      s   r=   c             C   s   t | jddd df| S )z'Turn a setting value into a dependency..r   r   Z	__first__)r=   split)rB   r   r   r   swappable_dependency   s    rE   N)Zdjango.db.migrationsr   Zdjango.db.migrations.utilsr   Zdjango.db.transactionr   
exceptionsr   r   r>   r=   rE   r   r   r   r   <module>   s    @