o
    ˜¨Êhœ  ã                   @   s,   d dl mZ d dlmZ G dd„ deƒZdS )é    )ÚBaseDatabaseSchemaEditor)ÚNOT_PROVIDEDc                       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edd„ ƒZe‡ fdd„ƒZdd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZ‡ fdd„Z‡ fd d!„Z‡ fd"d#„Z‡ fd$d%„Zd&d'„ Z‡ fd(d)„Z‡ fd*d+„Z ‡  Z!S ),ÚDatabaseSchemaEditorz+RENAME TABLE %(old_table)s TO %(new_table)szMODIFY %(column)s %(type)s NULLz#MODIFY %(column)s %(type)s NOT NULLzMODIFY %(column)s %(type)sz'MODIFY %(column)s %(type)s%(collation)sz(ALTER COLUMN %(column)s SET DEFAULT NULLz,ALTER TABLE %(table)s DROP COLUMN %(column)sz)ALTER TABLE %(table)s DROP INDEX %(name)szY, ADD CONSTRAINT %(name)s FOREIGN KEY (%(column)s) REFERENCES %(to_table)s(%(to_column)s)z/ALTER TABLE %(table)s DROP FOREIGN KEY %(name)sz DROP INDEX %(name)s ON %(table)sz?ALTER TABLE %(table)s RENAME INDEX %(old_name)s TO %(new_name)szGALTER TABLE %(table)s ADD CONSTRAINT %(name)s PRIMARY KEY (%(columns)s)z&ALTER TABLE %(table)s DROP PRIMARY KEYz9CREATE INDEX %(name)s ON %(table)s (%(columns)s)%(extra)sc                 C   s   | j jrdS dS )Nz8ALTER TABLE %(table)s DROP CONSTRAINT IF EXISTS %(name)sz)ALTER TABLE %(table)s DROP CHECK %(name)s)Ú
connectionÚmysql_is_mariadb©Úself© r	   úQ/var/www/html/env/lib/python3.10/site-packages/django/db/backends/mysql/schema.pyÚsql_delete_check#   s   z%DatabaseSchemaEditor.sql_delete_checkc                    s8   | j jr| j jdkrtƒ jS dS | j jdkrtƒ jS dS )N)é
   é   é   )é   r   é   zCALTER TABLE %(table)s CHANGE %(old_column)s %(new_column)s %(type)s)r   r   Úmysql_versionÚsuperÚsql_rename_columnr   ©Ú	__class__r	   r
   r   ,   s   þz&DatabaseSchemaEditor.sql_rename_columnc                 C   sV   | j  ¡  t|tƒr| dd¡}| j j  || j j j¡}t|tƒr)t|tƒr)| ¡ }|S )Nú%z%%)	r   Úensure_connectionÚ
isinstanceÚstrÚreplaceÚescapeÚencodersÚbytesÚdecode)r   ÚvalueÚquotedr	   r	   r
   Úquote_value7   s   


ÿz DatabaseSchemaEditor.quote_valuec                 C   s$   |  | j¡}|d uo| ¡ | jjv S ©N)Údb_typer   ÚlowerÚ_limited_data_types)r   Úfieldr#   r	   r	   r
   Ú_is_limited_data_typeC   s   þz*DatabaseSchemaEditor._is_limited_data_typec                 C   s   | j s|  |¡S dS )NF)Ú$_supports_limited_data_type_defaultsr'   ©r   r&   r	   r	   r
   Úskip_defaultJ   s   
z!DatabaseSchemaEditor.skip_defaultc                 C   s   |   |¡r| jjsdS dS )NTF)r'   r   r   r)   r	   r	   r
   Úskip_default_on_alterO   s   z*DatabaseSchemaEditor.skip_default_on_alterc                 C   s   | j jrdS | j jdkS )NT)r   r   é   )r   r   r   r   r	   r	   r
   r(   V   s   z9DatabaseSchemaEditor._supports_limited_data_type_defaultsc                    s(   | j js| jr|  |¡rdS tƒ  |¡S )Nz(%s))r   r   r(   r'   r   Ú_column_default_sqlr)   r   r	   r
   r-   ]   s   ÿþýz(DatabaseSchemaEditor._column_default_sqlc                    sf   t ƒ  ||¡ |  |¡r/|jd tfvr1|  |¡}|  d|  |jj	¡|  |j
¡dœ |g¡ d S d S d S )Nz%UPDATE %(table)s SET %(column)s = %%s)ÚtableÚcolumn)r   Ú	add_fieldr*   Údefaultr   Úeffective_defaultÚexecuteÚ
quote_nameÚ_metaÚdb_tabler/   )r   Úmodelr&   r2   r   r	   r
   r0   h   s   

þÿúþzDatabaseSchemaEditor.add_fieldc                    sV   t ƒ  ||¡s	dS | jj | j ¡ |jj¡}|dkr%| ¡ dkr%|j	r%dS |  
|¡ S )NFÚInnoDBÚ
ForeignKey)r   Ú_field_should_be_indexedr   ÚintrospectionÚget_storage_engineÚcursorr5   r6   Úget_internal_typeÚdb_constraintr'   )r   r7   r&   Ústorager   r	   r
   r:   x   s   ÿÿz-DatabaseSchemaEditor._field_should_be_indexedc                    sb   |j  |d ¡}| ¡ dkr&| j||jgdd�}|s&|  | j||gdd�¡ tƒ j||g|¢R Ž S )a˜  
        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.
        https://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.
        r   r9   T)ÚindexÚ )ÚfieldsÚsuffix)	r5   Ú	get_fieldr>   Ú_constraint_namesr/   r3   Ú_create_index_sqlr   Ú_delete_composed_index)r   r7   rC   ÚargsÚfirst_fieldÚconstraint_namesr   r	   r
   rH   Š   s   	
ÿÿz+DatabaseSchemaEditor._delete_composed_indexc                 C   s   |j r	|d7 }|S |d7 }|S )zt
        Keep the null property of the old field. If it has changed, it will be
        handled separately.
        z NULLz	 NOT NULL)Únull)r   r&   Únew_typer	   r	   r
   Ú_set_field_new_type_null_statusž   s
   ÿz4DatabaseSchemaEditor._set_field_new_type_null_statusc                    ó   |   ||¡}tƒ  ||||¡S r"   )rN   r   Ú_alter_column_type_sql)r   r7   Ú	old_fieldÚ	new_fieldrM   r   r	   r
   rP   ©   ó   z+DatabaseSchemaEditor._alter_column_type_sqlc                    rO   r"   )rN   r   Ú_rename_field_sql)r   r.   rQ   rR   rM   r   r	   r
   rT   ­   rS   z&DatabaseSchemaEditor._rename_field_sql)"Ú__name__Ú
__module__Ú__qualname__Úsql_rename_tableÚsql_alter_column_nullÚsql_alter_column_not_nullÚsql_alter_column_typeÚsql_alter_column_collateÚ sql_alter_column_no_default_nullÚsql_delete_columnÚsql_delete_uniqueÚsql_create_column_inline_fkÚsql_delete_fkÚsql_delete_indexÚsql_rename_indexÚsql_create_pkÚsql_delete_pkÚsql_create_indexÚpropertyr   r   r!   r'   r*   r+   r(   r-   r0   r:   rH   rN   rP   rT   Ú__classcell__r	   r	   r   r
   r      sF    ÿÿ


r   N)Údjango.db.backends.base.schemar   Údjango.db.modelsr   r   r	   r	   r	   r
   Ú<module>   s    