ó
i4Vdc           @   sÂ   d  d l  m Z d  d l m Z m Z d  d l m Z m Z m Z d  d l	 m
 Z
 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
 e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   settings(   t   BaseCommandt   CommandError(   t   DEFAULT_DB_ALIASt   connectionst
   migrations(   t   AmbiguityErrort   MigrationLoader(   t   SwappableTuple(   t   MigrationOptimizer(   t   MigrationWriter(   t   six(   t   get_docs_versiont   Commandc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sZ   Squashes an existing set of migrations (from first until specified) into a single new one.c         C   s–   | j  d d d ƒ| j  d d d  d d d d ƒ| j  d	 d d
 ƒ| j  d d d d d d t d d ƒ| j  d d d d d d d t d d ƒd  S(   Nt	   app_labelt   helps6   App label of the application to squash migrations for.t   start_migration_namet   defaultt   nargst   ?sG   Migrations will be squashed starting from and including this migration.t   migration_names?   Migrations will be squashed until and including this migration.s   --no-optimizet   actiont
   store_truet   destt   no_optimizes/   Do not try to optimize the squashed operations.s	   --noinputs
   --no-inputt   store_falset   interactives:   Tells Django to NOT prompt the user for input of any kind.(   t   add_argumentt   Nonet   Falset   True(   t   selft   parser(    (    s~   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/squashmigrations.pyt   add_arguments   s    c         K   sÂ  | j  d ƒ |  _ | j  d ƒ |  _ | d } | d } | d } | d } t t t ƒ } | | j k r~ t d | ƒ ‚ n  |  j | | | ƒ } g  | j	 j
 | j | j f ƒ D]- \ } }	 | | j k r² | j | |	 ƒ ^ q² }
 | re|  j | | | ƒ } | j | j | j ƒ } y |
 j | ƒ } |
 | }
 Wqet k
 rat d | | | f ƒ ‚ qeXn  |  j d	 k s}|  j r2|  j j |  j j d
 ƒ ƒ x% |
 D] } |  j j d | j ƒ q W|  j r2d  } xI | sæ| d k rt j j d ƒ } | sd } PqÓ| d	 j ƒ  } qÓW| d k r/d  Sq2n  g  } t ƒ  } t } xÁ |
 D]¹ } | j rst d t ƒ  ƒ ‚ n  | j | j ƒ x{ | j D]p } t  | t! ƒ rÔt" j# | j$ k rÄ| j% d' ƒ qý| j% | ƒ q| d	 | j k sí| r| j% | ƒ qqWt& } qNW| rH|  j d	 k r?|  j j |  j j d ƒ ƒ n  | } n¯ |  j d	 k rv|  j j |  j j d ƒ ƒ n  t' ƒ  } | j( | | j ƒ } |  j d	 k r÷t) | ƒ t) | ƒ k rÎ|  j j d ƒ q÷|  j j d t) | ƒ t) | ƒ f ƒ n  g  } xC |
 D]; } | j r&| j | j ƒ q| j* | j | j f ƒ qWt+ d t, j- f i | d 6| d 6| d 6ƒ } | r˜| d | j | j f | ƒ } n | d | j | ƒ } t | _. t/ | ƒ } t0 | j1 d ƒ  } | j | j2 ƒ  ƒ Wd  QX|  j d	 k r¾|  j j |  j j d | j1 ƒ ƒ |  j j d ƒ |  j j d  ƒ |  j j d! ƒ |  j j d" ƒ | j3 r¾|  j j |  j j d# ƒ ƒ |  j j d$ ƒ |  j j d% ƒ |  j j d& ƒ q¾n  d  S((   Nt	   verbosityR   R   R   R   R   sL   App '%s' does not have migrations (so squashmigrations on it makes no sense)s–   The migration '%s' cannot be found. Maybe it comes after the migration '%s'?
Have a look at:
  python manage.py showmigrations %s
to debug this issue.i    s%   Will squash the following migrations:s    - %st   yns   Do you wish to proceed? [yN] t   nt   ys¥   You cannot squash squashed migrations! Please transition it to a normal migration first: https://docs.djangoproject.com/en/%s/topics/migrations/#squashing-migrationst   __setting__t   AUTH_USER_MODELs   (Skipping optimization.)s   Optimizing...s     No optimizations possible.s0     Optimized from %s operations to %s operations.t	   Migrationt   dependenciest
   operationst   replacess   %s_squashed_%ss   0001_squashed_%st   wbs!   Created new squashed migration %ssC     You should commit this migration but leave the old ones in place;sD     the new migration will be used for new installs. Once you are suresI     all instances of the codebase have applied the migrations you squashed,s     you can delete them.s   Manual porting requiredsH     Your migrations contained functions that must be manually copied over,s3     as we could not safely copy their implementation.sC     See the comment at the top of the squashed migration for details.(   R&   R'   (4   t   getR"   R   R   R   R   t   migrated_appsR   t   find_migrationt   grapht   forwards_planR   t   namet   get_migrationt   indext
   ValueErrort   stdoutt   writet   stylet   MIGRATE_HEADINGR   R   t   movest   inputt   lowert   setR   R+   R   t   extendR*   R)   t
   isinstanceR   R    R'   t   settingt   addR   R	   t   optimizet   lent   appendt   typeR   R(   t   initialR
   t   opent   patht	   as_stringt   needs_manual_porting(   R   t   optionsR   R   R   R   t   loadert	   migrationt   alt   mnt   migrations_to_squasht   start_migrationt   startt   start_indext   answerR*   R)   t   first_migrationt
   smigrationt
   dependencyt   new_operationst	   optimizerR+   t   subclasst   new_migrationt   writert   fh(    (    s~   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/squashmigrations.pyt   handle   sÂ    



('	
		
				"	#	c         C   sh   y | j  | | ƒ SWnM t k
 r= t d | | f ƒ ‚ n' t k
 rc t d | | f ƒ ‚ n Xd  S(   NsJ   More than one migration matches '%s' in app '%s'. Please be more specific.s4   Cannot find a migration matching '%s' from app '%s'.(   t   get_migration_by_prefixR   R   t   KeyError(   R   RL   R   R2   (    (    s~   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/squashmigrations.pyR/   «   s    (   t   __name__t
   __module__R   R!   R^   R/   (    (    (    s~   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/squashmigrations.pyR      s   		N(   t   django.confR    t   django.core.management.baseR   R   t	   django.dbR   R   R   t   django.db.migrations.loaderR   R   t   django.db.migrations.migrationR   t   django.db.migrations.optimizerR	   t   django.db.migrations.writerR
   t   django.utilsR   t   django.utils.versionR   R   (    (    (    s~   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/squashmigrations.pyt   <module>   s   