ó
®â0_c           @  s  d  d l  m Z d  d l Z d  d l m Z d  d l m Z d  d l m Z d  d l	 m
 Z
 m Z d  d l m Z m Z d  d l m Z m Z d  d	 l m Z m Z m Z d  d
 l m Z d  d l m Z d  d l m Z d  d l m Z m Z d  d l m  Z  d e f d „  ƒ  YZ! d S(   iÿÿÿÿ(   t   unicode_literalsN(   t   OrderedDict(   t   import_module(   t   apps(   t   Tagst
   run_checks(   t   BaseCommandt   CommandError(   t   emit_post_migrate_signalt   emit_pre_migrate_signal(   t   DEFAULT_DB_ALIASt   connectionst   router(   t   MigrationAutodetector(   t   MigrationExecutor(   t   AmbiguityError(   t
   ModelStatet   ProjectState(   t   module_has_submodulet   Commandc           B  sA   e  Z d  Z d „  Z d „  Z d „  Z d e d „ Z d „  Z	 RS(   uM   Updates database schema. Manages both apps with migrations and those without.c         C  sì   | j  d d d d d ƒ| j  d d d d d ƒ| j  d d	 d
 d d d d t d d ƒ| j  d d
 d d d d t d d ƒ| j  d d
 d d d d t d d ƒ| j  d d
 d d d d t d d ƒ| j  d d
 d d d d d ƒd  S(   Nu	   app_labelt   nargsu   ?t   helpu5   App label of an application to synchronize the state.u   migration_nameup   Database state will be brought to the state after that migration. Use the name "zero" to unapply all migrations.u	   --noinputu
   --no-inputt   actionu   store_falset   destu   interactivet   defaultu:   Tells Django to NOT prompt the user for input of any kind.u
   --databaseu   storeu   databaseuH   Nominates a database to synchronize. Defaults to the "default" database.u   --fakeu
   store_trueu   fakeu5   Mark migrations as run without actually running them.u   --fake-initialu   fake_initialuÜ   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.u   --run-syncdbu
   run_syncdbu+   Creates tables for apps without migrations.(   t   add_argumentt   TrueR
   t   False(   t   selft   parser(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/migrate.pyt   add_arguments   s.    	c         K  s8   t  d t j g ƒ } | j t t |  ƒ j |   ƒ | S(   Nt   tags(   R   R   t   databaset   extendt   superR   t   _run_checks(   R   t   kwargst   issues(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/migrate.pyR#   <   s    c      
   O  s)  | d |  _  | d |  _ x9 t j ƒ  D]+ } t | j d ƒ r' t d | j ƒ q' q' W| d } t | } | j	 ƒ  t
 | |  j ƒ } | j j | ƒ | j j ƒ  } | rÝ d j d „  | j ƒ  Dƒ ƒ } t d | ƒ ‚ n  t }	 | d	 rÓ| d
 rÓ| d	 | d
 }
 } |
 | j j k r1t d |
 ƒ ‚ n  | d k rO|
 d  f g } n{ y | j j |
 | ƒ } WnM t k
 r‘t d | |
 f ƒ ‚ n' t k
 r·t d | |
 f ƒ ‚ n X|
 | j f g } t }	 nƒ | d	 rD| d	 }
 |
 | j j k rt d |
 ƒ ‚ n  g  | j j j ƒ  D] } | d |
 k r| ^ q} n | j j j ƒ  } | j | ƒ } | d ox| j j } |  j  d k rµ|  j j |  j j  d ƒ ƒ | rä|  j j |  j j! d ƒ d j t" | j j ƒ ƒ ƒ n  |	 r2|  j j |  j j! d ƒ d j t" t# d „  | Dƒ ƒ ƒ ƒ p*d ƒ qµ| d d d  k rx|  j j |  j j! d ƒ d | d d f ƒ qµ|  j j |  j j! d ƒ d | d d | d d f ƒ n  | j$ d t ƒ } | j } t% |  j  |  j | j& d | d | ƒ| rB|  j  d k r)|  j j |  j j  d ƒ ƒ n  |  j' | | j j ƒ n  |  j  d k rp|  j j |  j j  d  ƒ ƒ n  | s!|  j  d k r|  j j d! ƒ t( | j j) ƒ  t* j+ t ƒ ƒ } | j, d" | j j ƒ } | r|  j j |  j j- d# ƒ ƒ |  j j |  j j- d$ ƒ ƒ qn  t } t } n | d% } | d& } | j. | d | d' | j/ ƒ  d( | d) | ƒ} | j0 ƒ  | j } | j1 ƒ  K g  } x= | j2 D]2 } | j3 | j4 f } | j5 | ƒ | j6 | Œ  q’WWd  QX| j7 g  | D] } t8 j9 t j: | Œ  ƒ ^ qÛƒ t; |  j  |  j | j& d | d | ƒd  S(*   Nu	   verbosityu   interactiveu
   managementu   .managementu   databaseu   ; c         s  s.   |  ]$ \ } } d  d j  | ƒ | f Vq d S(   u   %s in %su   , N(   t   join(   t   .0t   appt   names(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/migrate.pys	   <genexpr>]   s   uŒ   Conflicting migrations detected; multiple leaf nodes in the migration graph: (%s).
To fix them run 'python manage.py makemigrations --merge'u	   app_labelu   migration_nameu"   App '%s' does not have migrations.u   zerouJ   More than one migration matches '%s' in app '%s'. Please be more specific.u4   Cannot find a migration matching '%s' from app '%s'.i    u
   run_syncdbi   u   Operations to perform:u     Synchronize unmigrated apps: u   , u     Apply all migrations: c         s  s   |  ] \ } } | Vq d  S(   N(    (   R'   t   at   n(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/migrate.pys	   <genexpr>–   s    u   (none)u     Unapply all migrations: u   %su     Target specific migration: u   %s, from %st   with_applied_migrationsR   t   planu&   Synchronizing apps without migrations:u   Running migrations:u     No migrations to apply.t   graphu^     Your models have changes that are not yet reflected in a migration, and so won't be applied.uk     Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.u   fakeu   fake_initialt   statet   faket   fake_initial(<   t	   verbosityt   interactiveR   t   get_app_configsR   t   moduleR   t   nameR   t   prepare_databaseR   t   migration_progress_callbackt   loadert   check_consistent_historyt   detect_conflictsR&   t   itemsR   R   t   migrated_appst   Nonet   get_migration_by_prefixR   t   KeyErrorR   R.   t
   leaf_nodest   migration_plant   unmigrated_appst   stdoutt   writet   stylet   MIGRATE_HEADINGt   MIGRATE_LABELt   sortedt   sett   _create_project_stateR	   t   aliast	   sync_appsR   t   project_stateR   t	   from_appst   changest   NOTICEt   migratet   clonet   clear_delayed_apps_cachet   bulk_updatet   real_modelst	   app_labelt
   name_lowert   appendt   unregister_modelt   render_multipleR   t
   from_modelt	   get_modelR   (   R   t   argst   optionst
   app_configt   dbt
   connectiont   executort	   conflictst   name_strt   target_app_labels_onlyRW   t   migration_namet   targetst	   migrationt   keyR-   t
   run_syncdbt   pre_migrate_statet   pre_migrate_appst   autodetectorRP   R0   R1   t   post_migrate_statet   post_migrate_appst
   model_keyst   model_statet	   model_keyt   model(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/migrate.pyt   handleA   sÎ    


	

8	 	0 	"	"
	

	
	,c         C  sS  |  j  d k rO|  j  d k } | d k rl | rB t j ƒ  |  _ n  |  j j d | d d ƒ|  j j ƒ  qO| d k rç | r• d t j ƒ  |  j n d } | rÄ |  j j |  j j d | ƒ ƒ qL|  j j |  j j d	 | ƒ ƒ qO| d
 k r5| rt j ƒ  |  _ n  |  j j d | d d ƒ|  j j ƒ  qO| d k r°| r^d t j ƒ  |  j n d } | r|  j j |  j j d | ƒ ƒ qL|  j j |  j j d	 | ƒ ƒ qO| d k rú| rÔt j ƒ  |  _ n  |  j j d d d ƒ|  j j ƒ  qO| d k rO| r#d t j ƒ  |  j n d } |  j j |  j j d | ƒ ƒ qOn  d  S(   Ni   u   apply_startu     Applying %s...t   endingu    u   apply_successu    (%.3fs)u    FAKEDu    OKu   unapply_startu     Unapplying %s...u   unapply_successu   render_startu     Rendering model states...u   render_successu    DONE(   R2   t   timet   startRD   RE   t   flushRF   t   SUCCESS(   R   R   Ri   R0   t   compute_timet   elapsed(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/migrate.pyR8   æ   s<    #######c           s¾  ˆ  j  ƒ   } ˆ  j j | ƒ ‰ Wd QXg  t j ƒ  D]H } | j d k	 r4 | j | k r4 | j t j	 | ˆ  j
 d t ƒf ^ q4 } ‡  ‡ f d †  ‰ t ‡ f d †  | Dƒ ƒ } |  j d k rÒ |  j j d ƒ n  ˆ  j ƒ  Ú } x® | j ƒ  D]  \ } }	 x‘ |	 D]‰ }
 |
 j j ˆ  ƒ sqn  |  j d k rQ|  j j d | |
 j j f ƒ n  |  j d k r}|  j j d	 |
 j j ƒ n  | j |
 ƒ qWqî W|  j d k r´|  j j d
 ƒ n  Wd QXd S(   u;   Run the old syncdb-style operation on a list of app_labels.Nt   include_auto_createdc           sM   |  j  } ˆ  j j } | | j ƒ ˆ k pK | j oK | | j j  j ƒ ˆ k S(   N(   t   _metat   introspectiont   table_name_convertert   db_tablet   auto_created(   Rt   t   optst	   converter(   Rb   t   tables(    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/migrate.pyt   model_installed  s    	c         3  s0   |  ]& \ } } | t  t ˆ  | ƒ ƒ f Vq d  S(   N(   t   listt   filter(   R'   t   app_namet
   model_list(   R†   (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/migrate.pys	   <genexpr>   s   i   u     Creating tables...
i   u       Processing %s.%s model
u       Creating table %s
u       Running deferred SQL...
(   t   cursorR   t   table_namesR   R4   t   models_moduleR>   t   labelR   t   get_migratable_modelsRL   R   R   R2   RD   RE   t   schema_editorR<   R~   t   can_migratet   object_nameR   t   create_model(   R   Rb   t
   app_labelsR‹   R`   t
   all_modelst   manifestt   editorR‰   RŠ   Rt   (    (   Rb   R†   R…   sI   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/migrate.pyRM     s0    H	N(
   t   __name__t
   __module__R   R   R#   Ru   R>   R   R8   RM   (    (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/migrate.pyR      s   	#		¥"("   t
   __future__R    Rw   t   collectionsR   t	   importlibR   t   django.appsR   t   django.core.checksR   R   t   django.core.management.baseR   R   t   django.core.management.sqlR   R	   t	   django.dbR
   R   R   t!   django.db.migrations.autodetectorR   t   django.db.migrations.executorR   t   django.db.migrations.loaderR   t   django.db.migrations.stateR   R   t   django.utils.module_loadingR   R   (    (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/migrate.pyt   <module>   s   