ó
i4Vdc           @  s0  d  d l  m Z d  d l 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 d  d l m Z m Z d  d l m Z m Z d  d	 l m Z 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 d  d l 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   call_command(   t   BaseCommandt   CommandError(   t   emit_post_migrate_signalt   emit_pre_migrate_signal(   t   DEFAULT_DB_ALIASt   connectionst   routert   transaction(   t   MigrationAutodetector(   t   MigrationExecutor(   t   AmbiguityError(   t   ProjectState(   t   RemovedInDjango110Warning(   t   module_has_submodulet   Commandc           B  s8   e  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 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   --listu   -lu   listu:   Show a list of all known migrations and which are applied.u   --run-syncdbu
   run_syncdbu+   Creates tables for apps without migrations.(   t   add_argumentt   TrueR	   t   False(   t   selft   parser(    (    su   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/migrate.pyt   add_arguments   s"    !c         O  sê  | j  d ƒ |  _ | j  d ƒ |  _ x9 t j ƒ  D]+ } t | j d ƒ r1 t d | j ƒ q1 q1 W| j  d ƒ } t	 | } | j  d t
 ƒ rt j d t d d	 ƒd  |  j _ t d
 d d | d rÐ | d g n d  d | d | j  d ƒ d | j  d ƒ d |  j d | j  d ƒ d |  j ƒS| j ƒ  t | |  j ƒ } | j j ƒ  } | rd j d „  | j ƒ  Dƒ ƒ } t d | ƒ ‚ n  t }	 | d ru| d ru| d | d }
 } |
 | j j k rÓt d |
 ƒ ‚ n  | d k rñ|
 d  f g } n{ y | j j |
 | ƒ } WnM t k
 r3t d | |
 f ƒ ‚ n' t k
 rYt d | |
 f ƒ ‚ n X|
 | j f g } t
 }	 nƒ | d ræ| d }
 |
 | j j k r®t d |
 ƒ ‚ n  g  | j j j  ƒ  D] } | d |
 k rÁ| ^ qÁ} n | j j j  ƒ  } | j! | ƒ } | j  d  ƒ o| j j" } |  j d! k rP|  j j# |  j$ j% d" ƒ ƒ | r…|  j j# |  j$ j& d# ƒ d$ j | j j" ƒ ƒ n  |	 rÍ|  j j# |  j$ j& d% ƒ d$ j t' d& „  | Dƒ ƒ ƒ pÅd' ƒ qP| d d! d  k r|  j j# |  j$ j& d( ƒ d) | d d f ƒ qP|  j j# |  j$ j& d* ƒ d+ | d d! | d d f ƒ n  t( |  j |  j | j) ƒ | r¶|  j d! k r|  j j# |  j$ j% d, ƒ ƒ n  |  j* | | j j" ƒ n  |  j d! k rä|  j j# |  j$ j% d- ƒ ƒ n  | s“| j+ ƒ  |  j d! k rÍ|  j j# d. ƒ t, | j j- ƒ  t. j/ t ƒ ƒ } | j0 d/ | j j ƒ } | r|  j j# |  j$ j1 d0 ƒ ƒ |  j j# |  j$ j1 d1 ƒ ƒ qqÍn: | j  d2 ƒ } | j  d3 ƒ } | j2 | | d4 | d5 | ƒt3 |  j |  j | j) ƒ d  S(6   Nu	   verbosityu   interactiveu
   managementu   .managementu   databaseu   listuI   The 'migrate --list' command is deprecated. Use 'showmigrations' instead.t
   stackleveli   u   showmigrationsu   --listt
   app_labelsu	   app_labelt   databaset   no_coloru   no_colort   settingsu   settingst   stdoutt	   tracebacku	   tracebackt	   verbosityu   ; c         s  s.   |  ]$ \ } } d  d j  | ƒ | f Vq d S(   u   %s in %su   , N(   t   join(   t   .0t   appt   names(    (    su   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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   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(    (    su   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/migrate.pys	   <genexpr>™   s    u   (none)u     Unapply all migrations: u   %su     Target specific migration: u   %s, from %su&   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   faket   fake_initial(4   t   getR&   t   interactiveR   t   get_app_configsR   t   moduleR   t   nameR
   R   t   warningst   warnR   t   NoneR$   t   endingR   t   prepare_databaseR   t   migration_progress_callbackt   loadert   detect_conflictsR'   t   itemsR   R   t   migrated_appst   get_migration_by_prefixR   t   KeyErrorR-   t
   leaf_nodest   migration_plant   unmigrated_appst   writet   stylet   MIGRATE_HEADINGt   MIGRATE_LABELt   setR   t   aliast	   sync_appst   check_replacementsR   t   project_stateR   t	   from_appst   changest   NOTICEt   migrateR   (   R   t   argst   optionst
   app_configt   dbt
   connectiont   executort	   conflictst   name_strt   target_app_labels_onlyt	   app_labelt   migration_namet   targetst	   migrationt   keyt   plant
   run_syncdbt   autodetectorRN   R.   R/   (    (    su   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/migrate.pyt   handle5   sÈ    
	

	

8		* 	"

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...R8   u    u   apply_successu    (%.3fs)u    FAKEDu    OKu   unapply_startu     Unapplying %s...u   unapply_successu   render_startu     Rendering model states...u   render_successu    DONE(   R&   t   timet   startR$   RD   t   flushRE   t   MIGRATE_SUCCESS(   R   R   R]   R.   t   compute_timet   elapsed(    (    su   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/migrate.pyR:   Î   s<    #######c           sB  ˆ  j  ƒ  } z$ˆ  j j | ƒ ‰ t ƒ  } g  t j ƒ  D]H } | j d k	 r7 | j | k r7 | j t	 j
 | ˆ  j d t ƒf ^ q7 } ‡  ‡ f d †  ‰ t ‡ f d †  | Dƒ ƒ } |  j d k rÕ |  j j d ƒ n  t j d ˆ  j d ˆ  j j ƒ 7g  } xé | j ƒ  D]Û \ }	 }
 xÌ |
 D]Ä } | j j ˆ  ƒ s;qn  |  j d k rm|  j j d	 |	 | j j f ƒ n  ˆ  j ƒ  Y } |  j d k r¨|  j j d
 | j j ƒ n  | j | ƒ | j | j ƒ g  | _ Wd QX| j | ƒ qWq
W|  j d k r|  j j d ƒ n  x | D] } | j | ƒ qWWd QXWd | j  ƒ  X| S(   u<   Runs the old syncdb-style operation on a list of app_labels.t   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(   t   modelt   optst	   converter(   RU   t   tables(    su   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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(   Rs   (    su   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/migrate.pys	   <genexpr>	  s   i   u     Creating tables...
t   usingt	   savepointi   u       Processing %s.%s model
u       Creating table %s
Nu       Running deferred SQL...
(!   t   cursorRk   t   table_namesRH   R   R2   t   models_moduleR7   t   labelR   t   get_migratable_modelsRI   R   R   R&   R$   RD   R   t   atomict   featurest   can_rollback_ddlR=   Rj   t   can_migratet   object_namet   schema_editorRm   t   create_modelt   extendt   deferred_sqlt   addt   executet   close(   R   RU   R    Rz   t   created_modelsRS   t
   all_modelst   manifestR‡   Rv   Rw   Ro   t   editort	   statement(    (   RU   Rs   Rr   su   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/migrate.pyRJ   ð   sF    	H"	N(	   t   __name__t
   __module__R   R   Rb   R7   R   R:   RJ   (    (    (    su   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/migrate.pyR      s
   		™"($   t
   __future__R    Rc   R5   t   collectionsR   t	   importlibR   t   django.appsR   t   django.core.managementR   t   django.core.management.baseR   R   t   django.core.management.sqlR   R   t	   django.dbR	   R
   R   R   t!   django.db.migrations.autodetectorR   t   django.db.migrations.executorR   t   django.db.migrations.loaderR   t   django.db.migrations.stateR   t   django.utils.deprecationR   t   django.utils.module_loadingR   R   (    (    (    su   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/migrate.pyt   <module>   s    "