ó
®â0_c           @   s:   d  d l  m Z d  d l m Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   BaseDatabaseSchemaEditor(   t   NOT_PROVIDEDt   DatabaseSchemaEditorc           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 RS(   s+   RENAME TABLE %(old_table)s TO %(new_table)ss   MODIFY %(column)s %(type)s NULLs#   MODIFY %(column)s %(type)s NOT NULLs   MODIFY %(column)s %(type)ss,   ALTER TABLE %(table)s DROP COLUMN %(column)ssC   ALTER TABLE %(table)s CHANGE %(old_column)s %(new_column)s %(type)ss)   ALTER TABLE %(table)s DROP INDEX %(name)ss/   ALTER TABLE %(table)s DROP FOREIGN KEY %(name)ss    DROP INDEX %(name)s ON %(table)ssG   ALTER TABLE %(table)s ADD CONSTRAINT %(name)s PRIMARY KEY (%(columns)s)s&   ALTER TABLE %(table)s DROP PRIMARY KEYc         C   s"   d d  l  } | j | | j j ƒ S(   Niÿÿÿÿ(   t   MySQLdb.converterst   escapet
   converterst   conversions(   t   selft   valuet   MySQLdb(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/mysql/schema.pyt   quote_value   s    c      
   C   sI   | j  |  j ƒ } | d
 k	 oH | j ƒ  d d d d d d d d d	 h	 k S(   s‚   
        MySQL doesn't accept default values for some data types and implicitly
        treats these columns as nullable.
        t   tinyblobt   blobt
   mediumblobt   longblobt   tinytextt   textt
   mediumtextt   longtextt   jsonN(   t   db_typet
   connectiont   Nonet   lower(   R   t   fieldR   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/mysql/schema.pyt   skip_default    s    	c         C   s“   t  t |  ƒ j | | ƒ |  j | ƒ r | j d  t f k r |  j | ƒ } |  j d i |  j	 | j
 j ƒ d 6|  j	 | j ƒ d 6| g ƒ n  d  S(   Ns%   UPDATE %(table)s SET %(column)s = %%st   tablet   column(   t   superR   t	   add_fieldR   t   defaultR   R   t   effective_defaultt   executet
   quote_namet   _metat   db_tableR   (   R   t   modelR   R   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/mysql/schema.pyR   /   s    $c         C   sw   t  t |  ƒ j | | ƒ } |  j j j |  j j ƒ  | j j ƒ } | d k rs | rs | j	 ƒ  d k rs | j
 rs t S| S(   Nt   InnoDBt
   ForeignKey(   R   R   t   _field_should_be_indexedR   t   introspectiont   get_storage_enginet   cursorR"   R#   t   get_internal_typet   db_constraintt   False(   R   R$   R   t   create_indext   storage(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/mysql/schema.pyR'   ;   s    	c         G   s   | j  j | d ƒ } | j ƒ  d k rt |  j | | j g d t ƒ} | st |  j |  j | | g d d ƒƒ qt n  t t	 |  ƒ j
 | | | Œ S(   s—  
        MySQL can remove an implicit FK index on a field when that field is
        covered by another index like a unique_together. "covered" here means
        that the more complex index starts like the simpler one.
        http://bugs.mysql.com/bug.php?id=37910 / Django ticket #24757
        We check here before removing the [unique|index]_together if we have to
        recreate a FK index.
        i    R&   t   indext   suffixt    (   R"   t	   get_fieldR+   t   _constraint_namesR   t   TrueR    t   _create_index_sqlR   R   t   _delete_composed_index(   R   R$   t   fieldst   argst   first_fieldt   constraint_names(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/mysql/schema.pyR7   J   s    	(c         C   s$   | j  r | d 7} n
 | d 7} | S(   st   
        Keep the null property of the old field. If it has changed, it will be
        handled separately.
        s    NULLs	    NOT NULL(   t   null(   R   R   t   new_type(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/mysql/schema.pyt   _set_field_new_type_null_statusZ   s    	
c         C   s1   |  j  | | ƒ } t t |  ƒ j | | | | ƒ S(   N(   R>   R   R   t   _alter_column_type_sql(   R   R   t	   old_fieldt	   new_fieldR=   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/mysql/schema.pyR?   e   s    c         C   s1   |  j  | | ƒ } t t |  ƒ j | | | | ƒ S(   N(   R>   R   R   t   _rename_field_sql(   R   R   R@   RA   R=   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/mysql/schema.pyRB   i   s    (   t   __name__t
   __module__t   sql_rename_tablet   sql_alter_column_nullt   sql_alter_column_not_nullt   sql_alter_column_typet   sql_delete_columnt   sql_rename_columnt   sql_delete_uniquet   sql_delete_fkt   sql_delete_indext   sql_create_pkt   sql_delete_pkR
   R   R   R'   R7   R>   R?   RB   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/mysql/schema.pyR      s&   							N(   t   django.db.backends.base.schemaR    t   django.db.modelsR   R   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/mysql/schema.pyt   <module>   s   