
 X4                 @   s   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z d d l m Z Gd	 d
   d
 e  Z d S)    )unicode_literals)Apps)models)DatabaseError)python_2_unicode_compatible)now   )MigrationSchemaMissingc               @   s   e  Z d  Z d Z e Gd d   d e j   Z d d   Z e	 d d    Z
 d d	   Z d
 d   Z d d   Z d d   Z d d   Z d S)MigrationRecordera  
    Deals with storing migration records in the database.

    Because this table is actually itself used for dealing with model
    creation, it's the one thing we can't do normally via migrations.
    We manually handle table creation/schema updating (using schema backend)
    and then have a floating model to do queries with.

    If a migration is unapplied its row is removed from the table. Having
    a row in the table always means a migration is applied.
    c               @   se   e  Z d  Z e j d d  Z e j d d  Z e j d e  Z	 Gd d   d  Z
 d d   Z d S)	zMigrationRecorder.Migration
max_length   defaultc               @   s%   e  Z d  Z e   Z d Z d Z d S)z MigrationRecorder.Migration.MetaZ
migrationsZdjango_migrationsN)__name__
__module____qualname__r   ZappsZ	app_labeldb_table r   r   K/home/ubuntu/projects/ifolica/build/django/django/db/migrations/recorder.pyMeta   s   	r   c             C   s   d |  j  |  j f S)NzMigration %s for %s)nameapp)selfr   r   r   __str__$   s    z#MigrationRecorder.Migration.__str__N)r   r   r   r   Z	CharFieldr   r   ZDateTimeFieldr   Zappliedr   r   r   r   r   r   	Migration   s
   r   c             C   s   | |  _  d  S)N)
connection)r   r   r   r   r   __init__'   s    zMigrationRecorder.__init__c             C   s   |  j  j j |  j j  S)N)r   ZobjectsZusingr   alias)r   r   r   r   migration_qs*   s    zMigrationRecorder.migration_qsc             C   s   |  j  j j |  j j j |  j j    k r1 d Sy, |  j j    } | j |  j   Wd QXWn5 t	 k
 r } z t
 d |   WYd d } ~ Xn Xd S)zF
        Ensures the table exists and has the correct schema.
        Nz1Unable to create the django_migrations table (%s))r   Z_metar   r   ZintrospectionZtable_namescursorZschema_editorZcreate_modelr   r	   )r   Zeditorexcr   r   r   ensure_schema.   s    -zMigrationRecorder.ensure_schemac             C   s0   |  j    t d d   |  j j d d  D  S)zE
        Returns a set of (app, name) of applied migrations.
        c             s   s   |  ] } t  |  Vq d  S)N)tuple).0xr   r   r   	<genexpr>B   s    z7MigrationRecorder.applied_migrations.<locals>.<genexpr>r   r   )r    setr   Zvalues_list)r   r   r   r   applied_migrations=   s    
z$MigrationRecorder.applied_migrationsc             C   s'   |  j    |  j j d | d |  d S)z7
        Records that a migration was applied.
        r   r   N)r    r   create)r   r   r   r   r   r   record_appliedD   s    
z MigrationRecorder.record_appliedc             C   s-   |  j    |  j j d | d |  j   d S)z9
        Records that a migration was unapplied.
        r   r   N)r    r   filterdelete)r   r   r   r   r   r   record_unappliedK   s    
z"MigrationRecorder.record_unappliedc             C   s   |  j  j   j   d S)zU
        Deletes all migration records. Useful if you're testing migrations.
        N)r   allr*   )r   r   r   r   flushR   s    zMigrationRecorder.flushN)r   r   r   __doc__r   r   ZModelr   r   propertyr   r    r&   r(   r+   r-   r   r   r   r   r
      s   r
   N)
__future__r   Zdjango.apps.registryr   Z	django.dbr   Zdjango.db.utilsr   Zdjango.utils.encodingr   Zdjango.utils.timezoner   
exceptionsr	   objectr
   r   r   r   r   <module>   s   