ó
®â0_c           @   sÎ   d  d l  Z  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ÿÿÿÿN(   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(    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/squashmigrations.pyt   add_arguments   s    c         K   sÁ  | d |  _  | d |  _ | d } | d } | d } | d } t t t ƒ } | | j k rt t d | ƒ ‚ n  |  j | | | ƒ } g  | j j	 | j
 | j f ƒ D]- \ } }	 | | j
 k r¨ | j | |	 ƒ ^ q¨ }
 | r[|  j | | | ƒ } | j | j
 | j ƒ } y |
 j | ƒ } |
 | }
 Wq[t k
 rWt d | | | f ƒ ‚ q[Xn  |  j  d	 k ss|  j r(|  j j |  j j d
 ƒ ƒ x% |
 D] } |  j j d | j ƒ q–W|  j r(d  } xI | sÜ| d k rt j j d ƒ } | sþd } PqÉ| d	 j ƒ  } qÉW| d k r%d  Sq(n  g  } t ƒ  } t } xÁ |
 D]¹ } | j ri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% } qDW| r>|  j  d	 k r5|  j j |  j j d ƒ ƒ n  | } n¯ |  j  d	 k rl|  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. | ƒ } t/ j0 | j1 d d 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   wt   encodings   utf-8s!   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   R"   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   iot   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(    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/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   RM   R   R2   (    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/squashmigrations.pyR/   ¶   s    (   t   __name__t
   __module__R   R!   R_   R/   (    (    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/squashmigrations.pyR      s   		(   RG   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   (    (    (    sR   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/squashmigrations.pyt   <module>   s   