ó
i4Vdc           @   sŠ   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	 e j
 d ƒ Z d „  Z d e f d	 „  ƒ  YZ d S(
   iÿÿÿÿN(   t   truncate_name(   t   atomic(   t   six(   t   force_bytess   django.db.backends.schemac         C   s3   t  d „  |  j j j Dƒ d „  | j j j Dƒ ƒ S(   Nc         s   s!   |  ] } | j  j s | Vq d  S(   N(   t   fieldt   many_to_many(   t   .0t   obj(    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pys	   <genexpr>   s    c         s   s!   |  ] } | j  j s | Vq d  S(   N(   R   R   (   R   R   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pys	   <genexpr>   s    (   t   zipt   modelt   _metat   related_objects(   t	   old_fieldt	   new_field(    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyt   _related_non_m2m_objects   s    t   BaseDatabaseSchemaEditorc           B   sô  e  Z d  Z d Z d Z d Z d Z d Z d Z d Z	 d Z
 d	 Z d
 Z d Z d Z d Z d Z d Z d Z d Z d Z d Z e Z d Z d Z d Z d Z d Z e d „ Z d „  Z d „  Z  g  d „ Z! d „  Z" e# d „  ƒ Z$ e d „ Z% d „  Z& d „  Z' d „  Z( d  „  Z) d! „  Z* d" „  Z+ d# „  Z, d$ „  Z- d% „  Z. d& „  Z/ d' „  Z0 d( „  Z1 d) „  Z2 e d* „ Z3 e d+ „ Z4 d, „  Z5 d- „  Z6 d. d/ „ Z7 d. e d0 „ Z8 d1 „  Z9 d2 „  Z: d3 „  Z; d4 „  Z< d5 „  Z= e e e e e e d6 „ Z> RS(7   sW  
    This class (and its subclasses) are responsible for emitting schema-changing
    statements to the databases - model creation/removal/alteration, field
    renaming, index fiddling, and so on.

    It is intended to eventually completely replace DatabaseCreation.

    This class should be used by creating an instance for each set of schema
    changes (e.g. a migration file), and by first calling start(),
    then the relevant actions, and then commit(). This is necessary to allow
    things like circular foreign key references - FKs will only be created once
    commit() is called.
    s'   CREATE TABLE %(table)s (%(definition)s)s1   ALTER TABLE %(old_table)s RENAME TO %(new_table)ss7   ALTER TABLE %(table)s SET TABLESPACE %(new_tablespace)ss   DROP TABLE %(table)s CASCADEs:   ALTER TABLE %(table)s ADD COLUMN %(column)s %(definition)ss!   ALTER TABLE %(table)s %(changes)ss%   ALTER COLUMN %(column)s TYPE %(type)ss%   ALTER COLUMN %(column)s DROP NOT NULLs$   ALTER COLUMN %(column)s SET NOT NULLs/   ALTER COLUMN %(column)s SET DEFAULT %(default)ss$   ALTER COLUMN %(column)s DROP DEFAULTs4   ALTER TABLE %(table)s DROP COLUMN %(column)s CASCADEsD   ALTER TABLE %(table)s RENAME COLUMN %(old_column)s TO %(new_column)ssF   UPDATE %(table)s SET %(column)s = %(default)s WHERE %(column)s IS NULLs?   ALTER TABLE %(table)s ADD CONSTRAINT %(name)s CHECK (%(check)s)s.   ALTER TABLE %(table)s DROP CONSTRAINT %(name)ssB   ALTER TABLE %(table)s ADD CONSTRAINT %(name)s UNIQUE (%(columns)s)sŒ   ALTER TABLE %(table)s ADD CONSTRAINT %(name)s FOREIGN KEY (%(column)s) REFERENCES %(to_table)s (%(to_column)s) DEFERRABLE INITIALLY DEFERREDs9   CREATE INDEX %(name)s ON %(table)s (%(columns)s)%(extra)ss   DROP INDEX %(name)ssG   ALTER TABLE %(table)s ADD CONSTRAINT %(name)s PRIMARY KEY (%(columns)s)c         C   s+   | |  _  | |  _ |  j r' g  |  _ n  d  S(   N(   t
   connectiont   collect_sqlt   collected_sql(   t   selfR   R   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyt   __init__H   s    			c         C   sA   g  |  _  |  j j j r= t |  j j ƒ |  _ |  j j ƒ  n  |  S(   N(   t   deferred_sqlR   t   featurest   can_rollback_ddlR   t   aliast	   __enter__(   R   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR   P   s
    	c         C   s\   | d  k r0 x! |  j D] } |  j | ƒ q Wn  |  j j j rX |  j j | | | ƒ n  d  S(   N(   t   NoneR   t   executeR   R   R   R   t   __exit__(   R   t   exc_typet	   exc_valuet	   tracebackt   sql(    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR   W   s
    c         C   s·   t  j d | | f ƒ |  j r‹ | j d ƒ r5 d n d } | d k	 rt |  j j | t t |  j	 | ƒ ƒ | ƒ q³ |  j j | | ƒ n( |  j
 j ƒ   } | j | | ƒ Wd QXd S(   sM   
        Executes the given SQL statement, with optional parameters.
        s   %s; (params %r)t   ;t    N(   t   loggert   debugR   t   endswithR   R   t   appendt   tuplet   mapt   quote_valueR   t   cursorR   (   R   R    t   paramst   endingR*   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR   `   s    	-c         C   s   |  j  j j | ƒ S(   N(   R   t   opst
   quote_name(   R   t   name(    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR.   p   s    c         G   s>   t  j ƒ  } x! | D] } | j t | ƒ ƒ q W| j ƒ  d  S(   sx   
        Generates a 32-bit digest of a set of arguments that can be used to
        shorten identifying names.
        i   (   t   hashlibt   md5t   updateR   t	   hexdigest(   t   clst   argst   ht   arg(    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyt   _digests   s    c   
      C   s«  | j  d |  j ƒ } | d } g  } | d
 k r5 d S| j } | oQ |  j | ƒ } | r» |  j | ƒ } | d
 k	 r» |  j j j rž | d |  j | ƒ 7} q¸ | d 7} | | g 7} q» n  | j	 ræ | j
 ræ |  j j j ræ t } n  | r	|  j j j r	| d 7} n | s| d 7} n  | j
 r2| d 7} n | j rH| d 7} n  | j pZ| j j }	 |	 r¡|  j j j r¡| j r¡| d |  j j j |	 d	 t ƒ7} n  | | f S(   s‹   
        Takes a field and returns its column definition.
        The field must already have had set_attributes_from_name called.
        R   t   types    DEFAULT %ss    NULLs	    NOT NULLs    PRIMARY KEYs    UNIQUEs    %st   inlineN(   NN(   t   db_parametersR   R   t   nullt   skip_defaultt   effective_defaultR   t   requires_literal_defaultst   prepare_defaultt   empty_strings_allowedt   primary_keyt!   interprets_empty_strings_as_nullst   Truet   implied_column_nullt   uniquet   db_tablespaceR
   t   supports_tablespacesR-   t   tablespace_sql(
   R   R	   R   t   include_defaultt	   db_paramsR    R+   R<   t   default_valuet
   tablespace(    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyt
   column_sql€   s:    
	
			&c         C   s   t  S(   s   
        Some backends don't accept default values for certain columns types
        (i.e. MySQL longtext and longblob).
        (   t   False(   R   R   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR=   °   s    c         C   s   t  d ƒ ‚ d S(   sU   
        Only used for backends which have requires_literal_defaults feature
        s€   subclasses of BaseDatabaseSchemaEditor for backends which have requires_literal_defaults must provide a prepare_default() methodN(   t   NotImplementedError(   R   t   value(    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR@   ·   s    c         C   s¡   | j  ƒ  r | j ƒ  } nR | j rg | j rg | j rg | j ƒ  d k rX t j ƒ  } qm t j ƒ  } n d } t j
 | ƒ rˆ | ƒ  } n  | j | |  j ƒ } | S(   sD   
        Returns a field's effective database default value
        t   BinaryFieldN(   t   has_defaultt   get_defaultR<   t   blankRA   t   get_internal_typeR   t   binary_typet	   text_typeR   t   callablet   get_db_prep_saveR   (   R   R   t   default(    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR>   À   s    c         C   s   t  ƒ  ‚ d S(   sY  
        Returns a quoted version of the value so it's safe to use in an SQL
        string. This is not safe against injection from user code; it is
        intended only for use in making SQL scripts or preparing default values
        for particularly tricky backends (defaults are not user-defined, though,
        so this is safe).
        N(   RP   (   R   RQ   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR)   Õ   s    c         C   s'  g  } g  } x×| j  j D]É} |  j | | ƒ \ } } | d k rI q n  | j d |  j ƒ } | d r} | d | d 7} n  | j d |  j ƒ } | r© | d | 7} n  | j | ƒ | j rp| j	 rp| j j
 j  j }	 | j j
 j  j | j j ƒ j }
 |  j j j r,|  j j |  j | | d ƒ ƒ qp|  j rp| d |  j i |  j |	 ƒ d 6|  j |
 ƒ d 67} qpn  | j d	 |  j | j ƒ | f ƒ | j ƒ  d
 k r |  j j j | j  j | j ƒ } | râ|  j j | ƒ qâq q WxX | j  j D]J } g  | D] } | j  j | ƒ j ^ q } |  j j |  j | | ƒ ƒ qóW|  j i |  j | j  j ƒ d 6d j | ƒ d 6} | j  j rµ|  j j j | j  j ƒ } | rµ| d | 7} qµn  |  j | | pÇd ƒ |  j j |  j  | ƒ ƒ x< | j  j! D]. } | j j" j  j# rñ|  j$ | j j" ƒ qñqñWd S(   s”   
        Takes a model and creates a table for it in the database.
        Will also create any accompanying indexes or unique constraints.
        R   t   checks    CHECK (%s)s    %ss   _fk_%(to_table)s_%(to_column)st    t   to_tablet	   to_columns   %s %st	   AutoFieldt   tables   , t
   definitionN(%   R
   t   local_fieldsRN   R   R;   R   t   db_type_suffixt   extendt   remote_fieldt   db_constraintR	   t   db_tablet	   get_fieldt
   field_namet   columnR   t   supports_foreign_keysR   R&   t   _create_fk_sqlt   sql_create_inline_fkR.   RV   R-   t   autoinc_sqlt   unique_togethert   _create_unique_sqlt   sql_create_tablet   joinRG   RI   R   t   _model_indexes_sqlt   local_many_to_manyt   throught   auto_createdt   create_model(   R   R	   t   column_sqlsR+   R   Rb   t   extra_paramsRK   t   col_type_suffixR^   R_   Ro   t   fieldst   columnsR    RI   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyRx   á   sX    
!"		!( 	c         C   sm   x< | j  j D]. } | j j j  j r |  j | j j ƒ q q W|  j |  j i |  j | j  j	 ƒ d 6ƒ d S(   s4   
        Deletes a model from the database.
        Ra   N(
   R
   Ru   Rf   Rv   Rw   t   delete_modelR   t   sql_delete_tableR.   Rh   (   R   R	   R   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR~   &  s
    c   	      C   sÅ   t  d „  | Dƒ ƒ } t  d „  | Dƒ ƒ } x7 | j | ƒ D]& } |  j | | i t d 6|  j ƒ q< WxX | j | ƒ D]G } g  | D] } | j j | ƒ j ^ qƒ } |  j |  j	 | | ƒ ƒ qv Wd S(   s¸   
        Deals with a model changing its unique_together.
        Note: The input unique_togethers must be doubly-nested, not the single-
        nested ["foo", "bar"] format.
        c         s   s   |  ] } t  | ƒ Vq d  S(   N(   R'   (   R   R|   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pys	   <genexpr>:  s    c         s   s   |  ] } t  | ƒ Vq d  S(   N(   R'   (   R   R|   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pys	   <genexpr>;  s    RF   N(
   t   sett
   differencet   _delete_composed_indexRD   t   sql_delete_uniqueR
   Ri   Rk   R   Rq   (	   R   R	   t   old_unique_togethert   new_unique_togethert   oldst   newsR|   R   R}   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyt   alter_unique_together4  s    $(c   	      C   sÈ   t  d „  | Dƒ ƒ } t  d „  | Dƒ ƒ } x7 | j | ƒ D]& } |  j | | i t d 6|  j ƒ q< Wx[ | j | ƒ D]J } g  | D] } | j j | ƒ ^ qƒ } |  j |  j | | d d ƒƒ qv Wd S(   s¶   
        Deals with a model changing its index_together.
        Note: The input index_togethers must be doubly-nested, not the single-
        nested ["foo", "bar"] format.
        c         s   s   |  ] } t  | ƒ Vq d  S(   N(   R'   (   R   R|   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pys	   <genexpr>J  s    c         s   s   |  ] } t  | ƒ Vq d  S(   N(   R'   (   R   R|   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pys	   <genexpr>K  s    t   indext   suffixt   _idxN(	   R€   R   R‚   RD   t   sql_delete_indexR
   Ri   R   t   _create_index_sql(	   R   R	   t   old_index_togethert   new_index_togetherR†   R‡   R|   t   field_namesR   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyt   alter_index_togetherD  s    $%c         C   s¤   g  | D] } | j  j | ƒ j ^ q } |  j | | |  } t | ƒ d k r€ t d t | ƒ | j  j d j | ƒ f ƒ ‚ n  |  j |  j	 | | | d ƒ ƒ d  S(   Ni   s1   Found wrong number (%s) of constraints for %s(%s)s   , i    (
   R
   Ri   Rk   t   _constraint_namest   lent
   ValueErrorRh   Rs   R   t   _delete_constraint_sql(   R   R	   R|   t   constraint_kwargsR    R   R}   t   constraint_names(    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR‚   T  s    (		c         C   sH   | | k r d S|  j  |  j i |  j | ƒ d 6|  j | ƒ d 6ƒ d S(   s6   
        Renames the table a model points to.
        Nt	   old_tablet	   new_table(   R   t   sql_rename_tableR.   (   R   R	   t   old_db_tablet   new_db_table(    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyt   alter_db_table_  s
    c         C   sN   |  j  |  j i |  j | j j ƒ d 6|  j | ƒ d 6|  j | ƒ d 6ƒ d S(   s;   
        Moves a model's table between tablespaces
        Ra   t   old_tablespacet   new_tablespaceN(   R   t   sql_retablespace_tableR.   R
   Rh   (   R   R	   t   old_db_tablespacet   new_db_tablespace(    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyt   alter_db_tablespacej  s    c         C   së  | j  r. | j j j j r. |  j | j j ƒ S|  j | | d t ƒ\ } } | d k r\ d S| j	 d |  j
 ƒ } | d r | d | d 7} n  |  j i |  j | j j ƒ d 6|  j | j ƒ d 6| d 6} |  j | | ƒ |  j | ƒ rP| j d k	 rP|  j i |  j | j j ƒ d 6|  j i |  j | j ƒ d 6d	 6} |  j | ƒ n  | j r…| j r…|  j j |  j | | g ƒ ƒ n  | j rÈ|  j
 j j rÈ| j rÈ|  j j |  j | | d
 ƒ ƒ n  |  j
 j j rç|  j
 j ƒ  n  d S(   s—   
        Creates a field on a model.
        Usually involves adding a column, but may involve adding a
        table instead (for M2M fields)
        RJ   NR   R\   s    CHECK (%s)Ra   Rk   Rb   t   changess   _fk_%(to_table)s_%(to_column)s(   R   Rf   Rv   R
   Rw   Rx   RN   RD   R   R;   R   t   sql_create_columnR.   Rh   Rk   R   R=   R[   t   sql_alter_columnt   sql_alter_column_no_defaultt   db_indexRF   R   R&   R   R   Rl   Rg   Rm   t   connection_persists_old_columnst   close(   R   R	   R   Rb   R+   RK   R    (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyt	   add_fieldt  s2    
			"!"c         C   s  | j  r. | j j j j r. |  j | j j ƒ S| j d |  j ƒ d d k rQ d S| j r« |  j	 | | j
 g d t ƒ} x0 | D]% } |  j |  j |  j | | ƒ ƒ q Wn  |  j i |  j | j j ƒ d 6|  j | j
 ƒ d 6} |  j | ƒ |  j j j r|  j j ƒ  n  d S(   s†   
        Removes a field from a model. Usually involves deleting a column,
        but for M2Ms may involve deleting a table.
        R   R9   Nt   foreign_keyRa   Rk   (   R   Rf   Rv   R
   Rw   R~   R;   R   R   R’   Rk   RD   R   R•   t   sql_delete_fkt   sql_delete_columnR.   Rh   R   R©   Rª   (   R   R	   R   t   fk_namest   fk_nameR    (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyt   remove_field¡  s    	&	c   	   	   C   s¨  | j  d |  j ƒ } | d } | j  d |  j ƒ } | d } | d k rY | j d k st | d k r | j d k r t d | | f ƒ ‚ nõ | d k r÷ | d k r÷ | j j r÷ | j j r÷ | j j j j r÷ | j j j j r÷ |  j | | | | ƒ S| d k rQ| d k rQ| j j rQ| j j rQ| j j j j rQ| j j j j rQd S| d k si| d k r‚t d | | f ƒ ‚ n  |  j	 | | | | | | | | ƒ d S(   sE  
        Allows a field's type, uniqueness, nullability, default, column,
        constraints etc. to be modified.
        Requires a copy of the old field as well so we can only perform
        changes that are required.
        If strict is true, raises errors if the old column does not match old_field precisely.
        R   R9   sq   Cannot alter field %s into %s - they do not properly define db_type (are you using a badly-written custom field?)Ns   Cannot alter field %s into %s - they are not compatible types (you cannot alter to or from M2M fields, or add or remove through= on M2M fields)(
   R;   R   R   Rf   R”   Rv   R
   Rw   t   _alter_many_to_manyt   _alter_field(	   R   R	   R   R   t   strictt   old_db_paramst   old_typet   new_db_paramst   new_type(    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyt   alter_field»  s2    	

c	   #   	   C   s“  t  ƒ  }	 | j rÂ | j rÂ |  j | | j g d t ƒ}
 | r| t |
 ƒ d k r| t d t |
 ƒ | j j	 | j f ƒ ‚ n  xC |
 D]8 } |	 j
 | j f ƒ |  j |  j |  j | | ƒ ƒ qƒ Wn  | j r|| j sè | j r|| j r||  j | | j g d t ƒ} | rIt | ƒ d k rIt d t | ƒ | j j	 | j f ƒ ‚ n  x0 | D]% } |  j |  j |  j | | ƒ ƒ qPWn  | j r| j r| | k rxw t | | ƒ D]c \ } } |  j | j | j j g d t ƒ} x0 | D]( } |  j |  j |  j | j | ƒ ƒ qáWqªWn  | j r–| j r–| j r–| j oA| j r–|  j | | j g d t ƒ} x0 | D]% } |  j |  j |  j | | ƒ ƒ qjWn  | d | d k rH| d rH|  j | | j g d t ƒ} | rt | ƒ d k rt d t | ƒ | j j	 | j f ƒ ‚ n  x0 | D]% } |  j |  j |  j | | ƒ ƒ qWn  | j | j k r‚|  j |  j | j j	 | | | ƒ ƒ n  g  } g  } g  } | | k rá|  j | j j	 | | | ƒ \ } } | j | ƒ | j | ƒ n  |  j | ƒ } |  j | ƒ } | | k o$| d k	 o$|  j | ƒ } | r¶|  j j j  r|| j |  j! i |  j" | j ƒ d	 6|  j# | ƒ d
 6g  f ƒ q¶| j |  j! i |  j" | j ƒ d	 6d d
 6| g f ƒ n  | j$ | j$ k rc|  j j j% rì| j& ƒ  d k rìqc| j$ r,| j |  j' i |  j" | j ƒ d	 6| d 6g  f ƒ qc| j |  j( i |  j" | j ƒ d	 6| d 6g  f ƒ n  | j) ƒ  o| j$ o| j$ } | sŽ| rÞ| s¡| | } n  |  j j j* rò| ròt+ t, | Œ  ƒ \ } } d j- | ƒ t. | g  ƒ f g } n  xH | D]@ \ } } |  j |  j/ i |  j" | j j	 ƒ d 6| d 6| ƒ qùW| rÞ|  j |  j0 i |  j" | j j	 ƒ d 6|  j" | j ƒ d	 6d d
 6| g ƒ xK | D]@ \ } } |  j |  j/ i |  j" | j j	 ƒ d 6| d 6| ƒ q”WqÞn  | rx' | D] \ } } |  j | | ƒ qëWn  | j r!| j s=| j r_| j r_| j r_|  j |  j1 | | j g ƒ ƒ n  | j rµ| j rµ| j rµ| j oŒ| j rµ|  j |  j2 | | g d d ƒƒ n  g  } | j rò| j rò| | k rò| j t | | ƒ ƒ n  | j r	| j r	|  j | d t ƒ} | rWt | ƒ d k rWt d t | ƒ | j j	 f ƒ ‚ n  x- | D]% } |  j |  j |  j3 | | ƒ ƒ q^W|  j |  j4 i |  j" | j j	 ƒ d 6|  j" |  j5 | | j g d d ƒƒ d 6|  j" | j ƒ d 6ƒ | j t | | ƒ ƒ n  xÉ | D]Á \ } } | j j6 d |  j ƒ }  |  d }! |  j | j j j	 | j | j |! ƒ \ } } |  j |  j/ i |  j" | j j j	 ƒ d 6| d d 6| d ƒ x$ | D] \ } } |  j | | ƒ q­	Wq	W| j r
|	 sô	| j sô	| j r
| j r
|  j |  j7 | | d ƒ ƒ n  | j r…
| j r…
| | k r…
xH | j8 j j9 D]4 }" |" j: sJ
|  j |  j7 |" j |" j d ƒ ƒ qJ
qJ
Wn  | d | d k r| d r|  j |  j; i |  j" | j j	 ƒ d 6|  j" |  j5 | | j g d d ƒƒ d 6|  j" | j ƒ d	 6| d d 6ƒ n  | rp|  j/ i |  j" | j j	 ƒ d 6|  j< i |  j" | j ƒ d	 6d 6} |  j | ƒ n  |  j j j= r|  j j> ƒ  n  d S(    s<   Actually perform a "physical" (non-ManyToMany) field update.R¬   i   s<   Found wrong number (%s) of foreign key constraints for %s.%sRF   s7   Found wrong number (%s) of unique constraints for %s.%sR‰   R\   s6   Found wrong number (%s) of check constraints for %s.%sRk   R[   s   %st	   CharFieldt	   TextFieldR9   s   , Ra   R¤   RŠ   t   _uniqRB   s0   Found wrong number (%s) of PK constraints for %st   _pkR/   R}   R   i    s   _fk_%(to_table)s_%(to_column)st   _fkt   _checkN(   Rº   R»   (?   R€   Rf   Rg   R’   Rk   RD   R“   R”   R
   Rh   t   addR   R•   R­   RF   RB   Rƒ   R   t   related_modelR   R¨   RŒ   t   sql_delete_checkt   _rename_field_sqlt   _alter_column_type_sqlR&   Re   R>   R   R=   R   R   R?   t   sql_alter_column_defaultR.   R@   R<   RC   RV   t   sql_alter_column_nullt   sql_alter_column_not_nullRS   t   supports_combined_altersR'   R   Rs   t   sumR¦   t   sql_update_with_defaultRq   R   t   sql_delete_pkt   sql_create_pkt   _create_index_nameR;   Rm   R	   R   R   t   sql_create_checkR§   R©   Rª   (#   R   R	   R   R   R¶   R¸   Rµ   R·   R´   t   fks_droppedR¯   R°   R—   t   constraint_namet   _old_relt   new_relt   rel_fk_namest   index_namest
   index_namet   actionst   null_actionst   post_actionst   fragmentt   other_actionst   old_defaultt   new_defaultt   needs_database_defaultt   four_way_default_alterationR    R+   t   rels_to_updatet   old_relt   rel_db_paramst   rel_typet   rel(    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR³   ä  sX   			&&		&-
&		&(					$		
	"
%	#	(
'				,	(		c         C   s1   |  j  i |  j | j ƒ d 6| d 6g  f g  f S(   sš  
        Hook to specialize column type alteration for different backends,
        for cases when a creation type is different to an alteration type
        (e.g. SERIAL in PostgreSQL, PostGIS fields).

        Should return two things; an SQL fragment of (sql, params) to insert
        into an ALTER TABLE statement, and a list of extra (sql, params) tuples
        to run once the field is altered.
        Rk   R9   (   t   sql_alter_column_typeR.   Rk   (   R   Ra   R   R   R¸   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyRÄ   ë  s
    	c         C   sî   | j  j j j | j  j j j k rX |  j | j  j | j  j j j | j  j j j ƒ n  |  j | j  j | j  j j j | j ƒ  ƒ | j  j j j | j ƒ  ƒ ƒ |  j | j  j | j  j j j | j ƒ  ƒ | j  j j j | j ƒ  ƒ ƒ d S(   s=   
        Alters M2Ms to repoint their to= endpoints.
        N(	   Rf   Rv   R
   Rh   R   R¹   Ri   t   m2m_reverse_field_namet   m2m_field_name(   R   R	   R   R   R´   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR²      s    $		R"   c   	      C   s“  t  | ƒ d k rO | rO t d | j j |  j | d ƒ f |  j j j ƒ  ƒ S| j j j d d ƒ j d d ƒ } d |  j | | Œ } |  j j j ƒ  pž d	 } d
 | | d | | f j d d ƒ j d d ƒ } t  | ƒ | k rd | d | | f } d | | t  | ƒ  | f } n  | d d k r:| d } n  t  | ƒ | k rnt	 j
 t | ƒ ƒ j ƒ  |  } n  | d j ƒ  rd | d  } n  | S(   sI   
        Generates a unique name for an index/unique constraint.
        i   s   %s_%si    t   "R"   t   .t   _s   _%siÈ   s	   %s_%s%s%ss   _%s%s%ss   %s%ss   D%siÿÿÿÿ(   R“   R    R
   Rh   R8   R   R-   t   max_name_lengtht   replaceR0   R1   R   R3   t   isdigit(	   R   R	   t   column_namesRŠ   t
   table_namet   index_unique_namet
   max_lengthRÕ   t   part(    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyRÍ     s(     $!"c   	         s  t  | ƒ d k r> | d j r> ˆ  j j j | d j ƒ } n0 | j j rh ˆ  j j j | j j ƒ } n d } | r d | } n  g  | D] } | j ^ qˆ } | p© ˆ  j } | i ˆ  j | j j	 ƒ d 6ˆ  j ˆ  j
 | | d | ƒƒ d 6d j ‡  f d	 †  | Dƒ ƒ d
 6| d 6S(   s¼   
        Return the SQL statement to create the index for one or several fields.
        `sql` can be specified if the syntax differs from the standard (GIS
        indexes, ...).
        i   i    R"   R]   Ra   RŠ   R/   s   , c         3   s   |  ] } ˆ  j  | ƒ Vq d  S(   N(   R.   (   R   Rk   (   R   (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pys	   <genexpr>K  s    R}   t   extra(   R“   RG   R   R-   RI   R
   Rk   t   sql_create_indexR.   Rh   RÍ   Rs   (	   R   R	   R|   RŠ   R    RI   R   R}   Ró   (    (   R   sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR   7  s    " c         C   sÝ   | j  j s% | j  j s% | j  j r) g  Sg  } xL | j  j D]> } | j r< | j r< | j |  j | | g d d ƒƒ q< q< WxX | j  j	 D]J } g  | D] } | j  j
 | ƒ ^ q˜ } | j |  j | | d d ƒƒ q‹ W| S(   s}   
        Return all index SQL statements (field indexes, index_together) for the
        specified model, as a list.
        RŠ   R"   R‹   (   R
   t   managedt   proxyt   swappedRc   R¨   RF   R&   R   t   index_togetherRi   (   R   R	   t   outputR   R   R|   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyRt   O  s    %)%#c         C   sH   |  j  i |  j | ƒ d 6|  j | j ƒ d 6|  j | j ƒ d 6| d 6S(   NRa   t
   old_columnt
   new_columnR9   (   t   sql_rename_columnR.   Rk   (   R   Ra   R   R   R¸   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyRÃ   `  s
    	c         C   s»   | j  j } | j } | j j j  j } | j j } | i | d 6| d 6} |  j i |  j | ƒ d 6|  j |  j | | g d | ƒƒ d 6|  j | ƒ d 6|  j | ƒ d 6|  j | ƒ d 6S(   NR^   R_   Ra   RŠ   R/   Rk   (   R
   Rh   Rk   t   target_fieldR	   t   sql_create_fkR.   RÍ   (   R   R	   R   RŠ   t
   from_tablet   from_columnR^   R_   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyRm   h  s    		%c            sc   ˆ  j  i ˆ  j | j j ƒ d 6ˆ  j ˆ  j | | d d ƒƒ d 6d j ‡  f d †  | Dƒ ƒ d 6S(   NRa   RŠ   R¼   R/   s   , c         3   s   |  ] } ˆ  j  | ƒ Vq d  S(   N(   R.   (   R   Rk   (   R   (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pys	   <genexpr>~  s    R}   (   t   sql_create_uniqueR.   R
   Rh   RÍ   Rs   (   R   R	   R}   (    (   R   sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyRq   z  s    	"c         C   s.   | i |  j  | j j ƒ d 6|  j  | ƒ d 6S(   NRa   R/   (   R.   R
   Rh   (   R   t   templateR	   R/   (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR•     s    c         C   sF  | r t  | ƒ n d } |  j j ƒ  % } |  j j j | | j j ƒ }	 Wd QXg  }
 xë |	 j ƒ  D]Ý \ } } | d k s‰ | | d k ra | d k	 r« | d | k r« qa n  | d k	 rÍ | d | k rÍ qa n  | d k	 rï | d | k rï qa n  | d k	 r| d | k rqa n  | d k	 r.| d r.qa n  |
 j	 | ƒ qa qa W|
 S(   sR   
        Returns all constraint names matching the columns and conditions
        NR}   RF   RB   R‰   R\   R¬   (
   t   listR   R   R*   t   introspectiont   get_constraintsR
   Rh   t   itemsR&   (   R   R	   Rí   RF   RB   R‰   R¬   R\   R*   t   constraintst   resultR/   t   infodict(    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR’   ‡  s$    $(?   t   __name__t
   __module__t   __doc__Rr   Rš   R    R   R¥   R¦   Rä   RÆ   RÇ   RÅ   R§   R®   Rû   RÊ   RÎ   RÂ   R   Rƒ   Rý   R   Rn   R­   Ró   RŒ   RÌ   RË   RO   R   R   R   R   R.   t   classmethodR8   RN   R=   R@   R>   R)   Rx   R~   Rˆ   R‘   R‚   R   R£   R«   R±   R¹   R³   RÄ   R²   RÍ   R   Rt   RÃ   Rm   Rq   R•   R’   (    (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyR      sz   				0						E						
	-	*ÿ 		 						(   R0   t   loggingt   django.db.backends.utilsR    t   django.db.transactionR   t   django.utilsR   t   django.utils.encodingR   t	   getLoggerR#   R   t   objectR   (    (    (    sl   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/schema.pyt   <module>   s   		