403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/django/db/backends/base/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/django/db/backends/base/__pycache__/schema.cpython-311.pyc
�

�|�e������ddlZddlmZddlmZmZmZmZmZmZddl	m
Z
mZddlm
Z
mZddlmZddlmZmZddlmZejd	��Zd
�Zd�Zd�ZGd
�d��ZdS)�N)�datetime)�Columns�Expressions�ForeignKeyName�	IndexName�	Statement�Table)�names_digest�split_identifier)�
Deferrable�Index)�Query)�TransactionManagementError�atomic)�timezonezdjango.db.backends.schemac�h�|j}|jrdS|jr|jdgkrdS|j|jvS)zz
    When altering the given field, must constraints on its model from the given
    relation be temporarily dropped?
    FNT)�field�many_to_many�primary_key�	to_fields�name)�relation�
altered_fieldrs   �@/usr/lib/python3/dist-packages/django/db/backends/base/schema.py�_is_relevant_relationrsI��

�N�E�����u�� ��U�_���%>�%>��t�����0�0�c�<�|j�ddd���S)NFT)�forward�reverse�include_hidden)�_meta�_get_fields)�models r�_all_related_fieldsr$ s���;�"�"�5�$�t�"�T�T�Trc����t�fd�t�j��D���fd�t�j��D����S)Nc3�<�K�|]}t|����|V��dS�N�r)�.0�obj�	old_fields  �r�	<genexpr>z+_related_non_m2m_objects.<locals>.<genexpr>(�5�����f�f��@U�VY�[d�@e�@e�f��f�f�f�f�f�frc3�<�K�|]}t|����|V��dSr'r()r)r*�	new_fields  �rr,z+_related_non_m2m_objects.<locals>.<genexpr>)r-r)�zipr$r#)r+r/s``r�_related_non_m2m_objectsr1$s\�����f�f�f�f�+�I�O�<�<�f�f�f�f�f�f�f�+�I�O�<�<�f�f�f���rc�|�eZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZeZd
ZdZdZdZdZdZdZdZdZeZdZeZdZdZdZeZdZ dZ!dZ"dZ#eZ$dZ%ddd �Z&d!�Z'd"�Z(ded$�Z)d%�Z*d&�Z+dfd'�Z,d(�Z-d)�Z.d*�Z/d+�Z0e1d,���Z2d-�Z3d.�Z4d/�Z5d0�Z6d1�Z7d2�Z8d3�Z9d4�Z:d5�Z;d6�Z<d7�Z=d8�Z>d9�Z?d:�Z@d;�ZAdfd<�ZB	dfd=�ZCd>�ZDdfd?�ZEd@�ZFdA�ZGdB�ZHdgdD�ZIdhdE�ZJdF�ZKdG�ZLdddCdCdd#dd#ddddH�dI�ZMdhdJ�ZNdK�ZOdL�ZPdM�ZQdN�ZRdO�ZSdP�ZTdQ�ZUdR�ZVdS�ZWdT�ZXdU�ZYdV�ZZ		didW�Z[		djdX�Z\		didY�Z]dZ�Z^d[�Z_d\�Z`d]�Za			dkd^�Zbdfd_�Zcd`�Zdda�Zedb�Zfdedc�ZgdS)l�BaseDatabaseSchemaEditorz�
    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.
    z'CREATE TABLE %(table)s (%(definition)s)z1ALTER TABLE %(old_table)s RENAME TO %(new_table)sz7ALTER TABLE %(table)s SET TABLESPACE %(new_tablespace)szDROP TABLE %(table)s CASCADEz:ALTER TABLE %(table)s ADD COLUMN %(column)s %(definition)sz!ALTER TABLE %(table)s %(changes)sz%ALTER COLUMN %(column)s TYPE %(type)sz%ALTER COLUMN %(column)s DROP NOT NULLz$ALTER COLUMN %(column)s SET NOT NULLz/ALTER COLUMN %(column)s SET DEFAULT %(default)sz$ALTER COLUMN %(column)s DROP DEFAULTz2ALTER COLUMN %(column)s TYPE %(type)s%(collation)sz4ALTER TABLE %(table)s DROP COLUMN %(column)s CASCADEzDALTER TABLE %(table)s RENAME COLUMN %(old_column)s TO %(new_column)szFUPDATE %(table)s SET %(column)s = %(default)s WHERE %(column)s IS NULLz"UNIQUE (%(columns)s)%(deferrable)szCHECK (%(check)s)z.ALTER TABLE %(table)s DROP CONSTRAINT %(name)sz"CONSTRAINT %(name)s %(constraint)sz?ALTER TABLE %(table)s ADD CONSTRAINT %(name)s CHECK (%(check)s)zPALTER TABLE %(table)s ADD CONSTRAINT %(name)s UNIQUE (%(columns)s)%(deferrable)sz|ALTER TABLE %(table)s ADD CONSTRAINT %(name)s FOREIGN KEY (%(column)s) REFERENCES %(to_table)s (%(to_column)s)%(deferrable)sNzQCREATE INDEX %(name)s ON %(table)s (%(columns)s)%(include)s%(extra)s%(condition)szOCREATE UNIQUE INDEX %(name)s ON %(table)s (%(columns)s)%(include)s%(condition)szDROP INDEX %(name)szGALTER TABLE %(table)s ADD CONSTRAINT %(name)s PRIMARY KEY (%(columns)s)zDROP PROCEDURE %(procedure)sFTc�n�||_||_|jrg|_|jjjo||_dSr')�
connection�collect_sql�
collected_sql�features�can_rollback_ddl�atomic_migration)�selfr5r6rs    r�__init__z!BaseDatabaseSchemaEditor.__init__cs?��$���&�����	$�!#�D�� $�� 8� I� T�f����rc��g|_|jr7t|jj��|_|j���|Sr')�deferred_sqlr:rr5�alias�	__enter__)r;s rr@z"BaseDatabaseSchemaEditor.__enter__lsB������ �	$� ���!6�7�7�D�K��K�!�!�#�#�#��rc��|�|jD]}|�|���|jr|j�|||��dSdSr')r>�executer:r�__exit__)r;�exc_type�	exc_value�	traceback�sqls     rrCz!BaseDatabaseSchemaEditor.__exit__ssg�����(�
"�
"�����S�!�!�!�!�� �	A��K� � ��9�i�@�@�@�@�@�	A�	Ar�c	�b�|js,|jjr |jjjstd���t
|��}t�d||||d����|jr||�	d��rdnd}|�B|j
�|tt|j|����z|z��dS|j
�||z��dS|j���5}|�||��ddd��dS#1swxYwYdS)z:Execute the given SQL statement, with optional parameters.ziExecuting DDL statements while in a transaction on databases that can't perform a rollback is prohibited.z%s; (params %r))�paramsrG)�extra�;�N)r6r5�in_atomic_blockr8r9r�str�logger�debug�endswithr7�append�tuple�map�quote_value�cursorrB)r;rGrJ�endingrWs     rrBz BaseDatabaseSchemaEditor.execute|s�����	�D�O�$C�	�D�O�Ld�Lu�	�,�?���
�
�#�h�h�����&��V�f�UX�;Y�;Y��Z�Z�Z���	,��<�<��,�,�5�R�R�#�F��!��"�)�)�3��s�4�;K�V�7T�7T�1U�1U�+U�Y_�*_�`�`�`�`�`��"�)�)�#��,�7�7�7�7�7���'�'�)�)�
,�V����s�F�+�+�+�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,����
,�
,�
,�
,�
,�
,s�D$�$D(�+D(c�@�|jj�|��Sr')r5�ops�
quote_name)r;rs  rr[z#BaseDatabaseSchemaEditor.quote_name�s����"�-�-�d�3�3�3rc�����jjD]>}�fd�|D��}�j����|�����?g}g}�jjD�]�}���|��\}}|��|��j���}	|	dr|d�j	|	zzz
}|�
�j���}
|
r|d|
zz
}|�|��|jr�|j
r�|jjjj}|jjj�|jj��j}�jr:|d�j��|����|��d�zzz
}n@�jjjr/�j����|d����|���|j���d|����|���d	vrK�jj��jj|j��}
|
r�j�|
�������fd
��jjD��}�j���jj��d�d�g|�|�RD����d
�z}�jjr3�jj��jj��}|r|d|zz
}||fS)z-Take a model and return its table definition.c�N��g|]!}�j�|��j��"SrH�r!�	get_field�column�r)rr#s  �r�
<listcomp>z6BaseDatabaseSchemaEditor.table_sql.<locals>.<listcomp>��,���O�O�O�u�u�{�,�,�U�3�3�:�O�O�OrN�r5�check� � %s)�to_table�	to_column�_fk_%(to_table)s_%(to_column)s)�	AutoField�BigAutoField�SmallAutoFieldc�<��g|]}|�������SrH)�constraint_sql)r)�
constraintr#r;s  ��rrbz6BaseDatabaseSchemaEditor.table_sql.<locals>.<listcomp>�s)���h�h�h�*�z�0�0���=�=�h�h�hr�, c3�K�|]}|�|V��	dSr'rH�r)rps  rr,z5BaseDatabaseSchemaEditor.table_sql.<locals>.<genexpr>�s(����#l�#l�:�ak�#l�J�#l�#l�#l�#l�#l�#lr)�table�
definition) r!�unique_togetherr>rS�_create_unique_sql�local_fields�
column_sql�
db_parametersr5�sql_check_constraint�db_type_suffix�extend�remote_field�
db_constraintr#�db_tabler_�
field_namer`�sql_create_inline_fkr[r8�supports_foreign_keys�_create_fk_sql�get_internal_typerZ�autoinc_sql�constraints�sql_create_table�join�
db_tablespace�tablespace_sql)r;r#�fields�columns�column_sqlsrJrru�extra_params�	db_params�col_type_suffixrhrir�r�rGr�s``               r�	table_sqlz"BaseDatabaseSchemaEditor.table_sql�sW�����k�1�	N�	N�F�O�O�O�O��O�O�O�G���$�$�T�%<�%<�U�G�%L�%L�M�M�M�M������[�-�#	:�#	:�E�'+���u�e�'D�'D�$�J���!���+�+�t��+�G�G�I���!�
J��c�D�$=�	�$I�I�I�
�#�2�2�d�o�2�N�N�O��
6��e�o�5�5�
��M�M�,�'�'�'��!�	
r�e�&9�	
r� �-�3�9�B��!�.�4�:�D�D�U�EW�Eb�c�c�j�	��,�r��#��(A�$(�O�O�H�$=�$=�%)�_�_�Y�%?�%?�E�E�)�#��J�J��_�-�C�r��%�,�,�T�-@�-@���Oo�-p�-p�q�q�q���������-�-�-�-��
� �
�
�
��&�&�(�(�,[�[�[�"�o�1�=�=�e�k�>R�TY�T`�a�a���:��%�,�,�[�9�9�9��h�h�h�h�h�PU�P[�Pg�h�h�h���#��_�_�U�[�%9�:�:��)�)�#l�#l�A]�;�A]�Q\�A]�A]�#l�#l�#l�l�l�'
�'
�
���;�$�	,�!�_�0�?�?���@Y�Z�Z�N��
,��s�^�+�+���F�{�rc�N�|�|j���}|d}g}|�dSt|dd��}|r||�|��z
}|j}|o-|�|��o|o|�|��}|rg|�|��}	d|�|��z}
|	�8|jj	j
r||
|�|	��zz
}n||
z
}||	gz
}|jr|j
s|jj	jrd}|r|jj	js|dz
}n|s|d	z
}|j
r|d
z
}n|jr|dz
}|jp|jj}|r?|jj	jr.|jr'|d|jj�|d�
��zz
}||fS)z�
        Take a field and return its column definition.
        The field must already have had set_attributes_from_name() called.
        rd�typeN)NN�db_collationz	 DEFAULT Tz NULLz	 NOT NULLz PRIMARY KEYz UNIQUErg)�inline)rzr5�getattr�_collate_sql�null�skip_default�skip_default_on_alter�effective_default�_column_default_sqlr8�requires_literal_defaults�prepare_default�empty_strings_allowedr�!interprets_empty_strings_as_nulls�implied_column_null�uniquer�r!�supports_tablespacesrZr�)r;r#r�include_defaultr�rGrJ�	collationr��
default_value�column_default�
tablespaces            rryz#BaseDatabaseSchemaEditor.column_sql�s$���'�'�4�?�'�C�C�	��������;��:��E�>�4�8�8�	��	0��4�$�$�Y�/�/�/�C��z��
�
=��!�!�%�(�(�(�
=�
�;�$�4�4�U�;�;�<�
	��	.� �2�2�5�9�9�M�(�4�+C�+C�E�+J�+J�J�N��(��?�+�E�.��>�D�,@�,@��,O�,O�O�O�C�C��>�)�C��}�o�-�F�
�'�	��0A�	���(�J�	��D��	���0�D�	��7�N�C�C��	��;��C���	��>�!�C�C�
�\�	��9��C��(�E�E�K�,E�
��	W�$�/�2�G�	W�E�L�	W��5�4�?�.�=�=�j�QU�=�V�V�V�V�C��F�{�rc��dS)z�
        Some backends don't accept default values for certain columns types
        (i.e. MySQL longtext and longblob).
        FrH�r;rs  rr�z%BaseDatabaseSchemaEditor.skip_default
�	��
�urc��dS)z�
        Some backends don't accept default values for certain columns types
        (i.e. MySQL longtext and longblob) in the ALTER COLUMN statement.
        FrHr�s  rr�z.BaseDatabaseSchemaEditor.skip_default_on_alterr�rc� �td���)zU
        Only used for backends which have requires_literal_defaults feature
        z�subclasses of BaseDatabaseSchemaEditor for backends which have requires_literal_defaults must provide a prepare_default() method��NotImplementedError�r;�values  rr�z(BaseDatabaseSchemaEditor.prepare_defaults��"�
P�
�
�	
rc��dS)z�
        Return the SQL to use in a DEFAULT clause. The resulting string should
        contain a '%s' placeholder for a default value.
        �%srHr�s  rr�z,BaseDatabaseSchemaEditor._column_default_sql$s	��
�trc���|���r|���}n�|js,|jr%|jr|���dkrd}n�d}n�t
|dd��st
|dd��rwtj��}|���}|dkr|�	��}n7|dkr|�
��}n|d	krtj��}nd}|S)
N�BinaryFieldrrM�auto_nowF�auto_now_add�	DateField�	TimeField�
DateTimeField)�has_default�get_defaultr��blankr�r�r�r�now�date�timer)r�default�
internal_types   r�_effective_defaultz+BaseDatabaseSchemaEditor._effective_default+s�������	��'�'�)�)�G�G���	���	��0K�	��&�&�(�(�M�9�9�������
�U�J��
.�
.�
	�'�%��QV�2W�2W�
	��l�n�n�G�!�3�3�5�5�M���+�+�!�,�,�.�.����+�-�-�!�,�,�.�.����/�1�1�"�,�.�.����G��rc�^�|�|�|��|j��S)z2Return a field's effective database default value.)�get_db_prep_saver�r5r�s  rr�z*BaseDatabaseSchemaEditor.effective_defaultBs(���%�%�d�&=�&=�e�&D�&D�d�o�V�V�Vrc��t���)aX
        Return 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).
        r�r�s  rrVz$BaseDatabaseSchemaEditor.quote_valueFs��"�#�#�#rc�H�|�|��\}}|�||pd��|j�|�|����|jjD]7}|jjjj	r|�
|jj���8dS)zr
        Create a table and any accompanying indexes or unique constraints for
        the given `model`.
        N)r�rBr>r}�_model_indexes_sqlr!�local_many_to_manyr~�through�auto_created�create_model)r;r#rGrJrs     rr�z%BaseDatabaseSchemaEditor.create_modelRs���
�n�n�U�+�+���V����S�&�.�D�)�)�)�	
�� � ��!8�!8��!?�!?�@�@�@��[�3�	>�	>�E��!�)�/�<�
>��!�!�%�"4�"<�=�=�=��	>�	>rc���|jjD]7}|jjjjr|�|jj���8|�|jd|�|jj	��iz��t|j��D]P}t|t��r9|�|jj	��r|j�|���QdS)z!Delete a model from the database.rtN)r!r�r~r�r��delete_modelrB�sql_delete_tabler[r��listr>�
isinstancer�references_table�remove)r;r#rrGs    rr�z%BaseDatabaseSchemaEditor.delete_modelcs����[�3�	>�	>�E��!�)�/�<�
>��!�!�%�"4�"<�=�=�=��	
���T�*��T�_�_�U�[�%9�:�:�.
�
�	�	�	���)�*�*�	.�	.�C��#�y�)�)�
.�c�.B�.B�5�;�CW�.X�.X�
.��!�(�(��-�-�-��	.�	.rc��|jr|jjjsdS|�|�||��d���dS)zAdd an index on a model.N�rJ)�contains_expressionsr5r8�supports_expression_indexesrB�
create_sql�r;r#�indexs   r�	add_indexz"BaseDatabaseSchemaEditor.add_indexssT��
�&�	���(�D�	��4�	
���U�%�%�e�T�2�2�4��@�@�@�@�@rc��|jr|jjjsdS|�|�||����dS)zRemove an index from a model.N)r�r5r8r�rB�
remove_sqlr�s   r�remove_indexz%BaseDatabaseSchemaEditor.remove_index~sN��
�&�	���(�D�	��4����U�%�%�e�T�2�2�3�3�3�3�3rc�h�|�||��}|r|�|d���dSdS)zAdd a constraint to a model.Nr�)r�rB�r;r#rprGs    r�add_constraintz'BaseDatabaseSchemaEditor.add_constraint�sG���#�#�E�4�0�0���	+�
�L�L��T�L�*�*�*�*�*�	+�	+rc�d�|�||��}|r|�|��dSdS)z!Remove a constraint from a model.N)r�rBr�s    r�remove_constraintz*BaseDatabaseSchemaEditor.remove_constraint�sA���#�#�E�4�0�0���	��L�L�������	�	rc�D��d�|D��}d�|D��}|�|��D]!}|��|ddi|j���"|�|��D]9}�fd�|D��}|�|��|�����:dS)z�
        Deal with a model changing its unique_together. The input
        unique_togethers must be doubly-nested, not the single-nested
        ["foo", "bar"] format.
        c�,�h|]}t|����SrH�rT�r)r�s  r�	<setcomp>zABaseDatabaseSchemaEditor.alter_unique_together.<locals>.<setcomp>����@�@�@�&��f�
�
�@�@�@rc�,�h|]}t|����SrHr�r�s  rr�zABaseDatabaseSchemaEditor.alter_unique_together.<locals>.<setcomp>�r�rr�Tc�N��g|]!}�j�|��j��"SrHr^ras  �rrbzBBaseDatabaseSchemaEditor.alter_unique_together.<locals>.<listcomp>�rcrN)�
difference�_delete_composed_index�sql_delete_uniquerBrw)r;r#�old_unique_together�new_unique_together�olds�newsr�r�s `      r�alter_unique_togetherz.BaseDatabaseSchemaEditor.alter_unique_together�s����A�@�,?�@�@�@��@�@�,?�@�@�@���o�o�d�+�+�	a�	a�F��'�'��v��$�7G��I_�`�`�`�`��o�o�d�+�+�	B�	B�F�O�O�O�O��O�O�O�G��L�L��0�0���@�@�A�A�A�A�	B�	Brc�J��d�|D��}d�|D��}|�|��D]"}|��|ddd�|j���#|�|��D];}�fd�|D��}|�|��|d������<d	S)
z�
        Deal with a model changing its index_together. The input
        index_togethers must be doubly-nested, not the single-nested
        ["foo", "bar"] format.
        c�,�h|]}t|����SrHr�r�s  rr�z@BaseDatabaseSchemaEditor.alter_index_together.<locals>.<setcomp>����?�?�?�&��f�
�
�?�?�?rc�,�h|]}t|����SrHr�r�s  rr�z@BaseDatabaseSchemaEditor.alter_index_together.<locals>.<setcomp>�r�rTF)r�r�c�D��g|]}�j�|����SrH�r!r_ras  �rrbzABaseDatabaseSchemaEditor.alter_index_together.<locals>.<listcomp>��)���L�L�L�u�e�k�+�+�E�2�2�L�L�Lr�_idx�r��suffixN)r�r��sql_delete_indexrB�_create_index_sql)r;r#�old_index_together�new_index_togetherr�r�r��field_namess `      r�alter_index_togetherz-BaseDatabaseSchemaEditor.alter_index_together�s����@�?�,>�?�?�?��?�?�,>�?�?�?���o�o�d�+�+�	�	�F��'�'����%�0�0��%�	
�
�
�
� �?�?�4�0�0�	V�	V�K�L�L�L�L��L�L�L�F��L�L��/�/��f�V�/�T�T�U�U�U�U�	V�	Vrc
���d��jjD��}d��jjD��}�fd�|D��}|j�|fd||zi|��}t	|��dkrCtdt	|���d�jj�dd	�|���d
����|�|�	|�|d����dS)Nc��h|]	}|j��
SrH�rrss  rr�zBBaseDatabaseSchemaEditor._delete_composed_index.<locals>.<setcomp>�s�� [� [� [�Z��� [� [� [rc��h|]	}|j��
SrHrrss  rr�zBBaseDatabaseSchemaEditor._delete_composed_index.<locals>.<setcomp>�s��R�R�R�
�J�O�R�R�Rrc�N��g|]!}�j�|��j��"SrHr^ras  �rrbzCBaseDatabaseSchemaEditor._delete_composed_index.<locals>.<listcomp>�s,���K�K�K�5�5�;�(�(��/�/�6�K�K�Kr�exclude��Found wrong number (z) of constraints for �(rq�)r)
r!r��indexes�_constraint_names�len�
ValueErrorr�r�rB�_delete_constraint_sql)	r;r#r��constraint_kwargsrG�meta_constraint_names�meta_index_namesr��constraint_namess	 `       rr�z/BaseDatabaseSchemaEditor._delete_composed_index�s��� [� [�5�;�CZ� [� [� [��R�R�e�k�>Q�R�R�R��K�K�K�K�F�K�K�K��1�4�1��7�
�
�$9�<L�$L�
��
�
���� � �A�%�%��*��$�%�%�%�%���$�$�$��	�	�'�"�"�"�"����
�
	
���T�0�0��e�=M�a�=P�Q�Q�R�R�R�R�Rrc��||ks;|jjjr,|���|���krdS|�|j|�|��|�|��d�z��|jD]-}t|t��r|�
||���.dS)z#Rename the table a model points to.N)�	old_table�	new_table)r5r8�ignores_table_name_case�lowerrB�sql_rename_tabler[r>r�r�rename_table_references)r;r#�old_db_table�new_db_tablerGs     r�alter_db_tablez'BaseDatabaseSchemaEditor.alter_db_table�s����L�(�(�
�_�
%�
=�
)��"�"�$�$��(:�(:�(<�(<�<�<��F����T�*�����6�6�����6�6�.
�.
�
�	�	�	�
�$�	H�	H�C��#�y�)�)�
H��+�+�L�,�G�G�G��	H�	Hrc���|�|j|�|jj��|�|��|�|��d�z��dS)z)Move a model's table between tablespaces.)rt�old_tablespace�new_tablespaceN)rB�sql_retablespace_tabler[r!r�)r;r#�old_db_tablespace�new_db_tablespaces    r�alter_db_tablespacez,BaseDatabaseSchemaEditor.alter_db_tablespace�sj�����T�0��_�_�U�[�%9�:�:�"�o�o�.?�@�@�"�o�o�.?�@�@�4
�4
�
�	�	�	�	�	rc
�V�|jr5|jjjjr|�|jj��S|�||d���\}}|�dS|�|j���}|dr|d|j	|zzz
}|j�rY|jj
j�rG|j�r?d}|j
�r|jjjj}|jjj�|jj��j}t'|jj��\}	}
|d|j
|�|||��|	rd|�|	��znd	|�|j��|�|��|�|��|jj���d
�zzz
}n/|j�|�|||����|j|�|jj��|�|j��|d�z}|�||��|�|��sq|�|���\|�|d|d���\}}|j |�|jj��|d
�z}|�||��|j�!|�"||����|jj
j#r|j�$��dSdS)z�
        Create a field on a model. Usually involves adding a column, but may
        involve adding a table instead (for M2M fields).
        T)r�Nrdrerfrjz%s.rM)r�	namespacer`rhri�
deferrable)rtr`ru��drop�rt�changes)%rr~r�r!r�r�ryrzr5r{r8r�r�sql_create_column_inline_fkr#r�r_r�r`r�_fk_constraint_namer[rZ�deferrable_sqlr>rSr��sql_create_columnrBr�r��_alter_column_default_sql�sql_alter_columnr}�_field_indexes_sql�connection_persists_old_columns�close)
r;r#rrurJr��constraint_suffixrhrir*�_rG�changes_sqls
             r�	add_fieldz"BaseDatabaseSchemaEditor.add_field�s6����	A�%�"4�"<�"B�"O�	A��$�$�U�%7�%?�@�@�@�!�_�_�U�E�4�_�P�P��
�F����F��'�'�4�?�'�C�C�	��W��	F��#�� 9�I� E�E�E�J���	_�$�/�":�"P�	_�UZ�Uh�	_� @���/�
_� �-�3�9�B��!�.�4�:�D�D�U�EW�Eb�c�c�j�	�/���0D�E�E��	�1��c�D�$D� �4�4�U�E�CT�U�U�GP�!X������)C�)C�!C�!C�VX�"�o�o�e�l�;�;� $���� 9� 9�!%����!;�!;�"&�/�"5�"D�"D�"F�"F�
H�H�%���
�
��!�(�(��)<�)<�U�E�K\�)]�)]�^�^�^��$��_�_�U�[�%9�:�:��o�o�e�l�3�3�$�(
�(
�
��
	
���S�&�!�!�!��)�)�%�0�0�	&�T�5K�5K�E�5R�5R�5^�"&�"@�"@���e�Z^�"@�"_�"_��K���'������)=�>�>�&�+�+��C�
�L�L��f�%�%�%��� � ��!8�!8���!F�!F�G�G�G��?�#�C�	$��O�!�!�#�#�#�#�#�	$�	$rc�B�|jr5|jjjjr|�|jj��S|�|j���d�dS|jrL|�||j	gd���}|D]+}|�
|�||�����,|j|�
|jj��|�
|j	��d�z}|�
|��|jjjr|j���t%|j��D]V}t)|t*��r?|�|jj|j	��r|j�|���WdS)z�
        Remove a field from a model. Usually involves deleting a column,
        but for M2Ms may involve deleting a table.
        rdr�NT��foreign_key)rtr`)rr~r�r!r�r�rzr5rr`rB�_delete_fk_sql�sql_delete_columnr[r�r8r7r8r�r>r�r�references_columnr�)r;r#r�fk_names�fk_namerGs      r�remove_fieldz%BaseDatabaseSchemaEditor.remove_fields�����	A�%�"4�"<�"B�"O�	A��$�$�U�%7�%?�@�@�@����$�/��:�:�6�B�J��F���	B��-�-�e�e�l�^�QU�-�V�V�H�#�
B�
B�����T�0�0���@�@�A�A�A�A��$��_�_�U�[�%9�:�:��o�o�e�l�3�3�(
�(
�
��	
���S�����?�#�C�	$��O�!�!�#�#�#���)�*�*�	.�	.�C��#�y�)�)�
.�c�.C�.C�E�K�DX�Z_�Zf�.g�.g�
.��!�(�(��-�-�-��	.�	.rc
���|�||��sdS|�|j���}|d}|�|j���}|d}|�|j�	|�|j�t	d|�d|�d����|�^|�\|jjrP|jjrD|jjjjr.|jjjjr|�||||��S|�H|�F|jjr:|jjr.|jjjjs|jjjjsdS|�|�t	d|�d|�d����|�	||||||||��dS)a'
        Allow a field's type, uniqueness, nullability, default, column,
        constraints, etc. to be modified.
        `old_field` is required to compute the necessary changes.
        If `strict` is True, raise errors if the old column does not match
        `old_field` precisely.
        Nrdr�zCannot alter field z into zT - they do not properly define db_type (are you using a badly-written custom field?)zr - they are not compatible types (you cannot alter to or from M2M fields, or add or remove through= on M2M fields))
�_field_should_be_alteredrzr5r~rr�r!r��_alter_many_to_many�_alter_field)	r;r#r+r/�strict�
old_db_params�old_type�
new_db_params�new_types	         r�alter_fieldz$BaseDatabaseSchemaEditor.alter_field8s����,�,�Y�	�B�B�	��F�!�/�/�4�?�/�K�K�
� ��(��!�/�/�4�?�/�K�K�
� ��(��
�
�)�"8�"@��!�i�&<�&D��*����I�I�I�'���
�
�
�(�"2��&�.�#3�3<�3I�3Q�#3��&�.�4�A�#3��&�.�4�A�#3��+�+�E�9�i��P�P�P�
�
�(�"2��&�.�#3�3<�3I�3Q�#3��*�2�8�E�#3��*�2�8�E�#3�

�F�
�
��!1��*�.7�Y�Y�	�	�	�C���
�	
���%��I�x��'���	@�	@�	@�	@�	@rc	��t��}	|jjjr�|jr�|jr�|�||jgd���}
|rGt|
��dkr4tdt|
���d|j
j�d|j�����|
D]F}|	�|jf��|�
|�||�����G|jr�|jr|�||��r�d�|j
jD��}|�||jgdd|�	��}
|rGt|
��dkr4tdt|
���d
|j
j�d|j�����|
D]+}|�
|�||�����,|jjjo!|jr|jp
|jo|jo||k}|rqt)||��D]`\}}|�|j|jjgd���}|D]0}|�
|�|j|�����1�a|jr�|js||jr|jrnd�|j
jD��}|�||jgdt2j|���}|D]+}|�
|�||�����,|d
|d
kr�|d
r�d�|j
jD��}|�||jgd|���}
|rGt|
��dkr4tdt|
���d|j
j�d|j�����|
D]+}|�
|�||�����,|j|jkr|�
|�|j
j|||����|jD]B}t?|t@��r+|�!|j
j|j|j���Cg}g}g}tE|dd��}tE|dd��}||kr.|�#||||��}|�$|��nK||krE|�%||||��\}}|�$|��|�&|��d}|j'rz|j'ss|�(|��}|�(|��} |�)|��s4|| kr.| �,d}|�$|�*|||����|j'|j'kr.|�+|||��}|r|�$|��|�,��o|j'o|j'}!|s|�r?|!s||z}|jjj-rA|r?t]t_|���\}}"d�0|��tc|"g��fg}|D]C\}}"|�
|j2|�3|j
j��|d�z|"���D|!r�|�
|j4|�3|j
j��|�3|j��dd�z| g��|D]C\}}"|�
|j2|�3|j
j��|d�z|"���D|r|D]\}}"|�
||"���|jr|js|�5||��|�6||��r/|�
|�7||jg����|jr|jr9|jr2|js+|�
|�8||g�����g}#|r#|#�&t)||����|�||��rL|�
|�9||����|#�&t)||����|#D]�\}$}|j�:|j���}%|%d}&|�%|j|$j|j|&��\}}|�
|j2|�3|jj
j��|dd�z|d��|D]\}}"|�
||"�����|jjjrH|jrA|	s|jr|js1|jr*|�
|�;||d����|rd|j<j
j=D]R}'t}|'|��r@|'jjr4|�
|�;|'j|'jd�����S|d
|d
kr`|d
rX|�?|j
j|jgd���}|�
|�@|||d
����|r\|�*|||d���\}(}"|j2|�3|j
j��|(d�z}|�
||"��|jjjAr|j�B��dSdS) z3Perform a "physical" (non-ManyToMany) field update.Tr>rrz!) of foreign key constraints for �.c��h|]	}|j��
SrHrrss  rr�z8BaseDatabaseSchemaEditor._alter_field.<locals>.<setcomp>z���$_�$_�$_��Z�_�$_�$_�$_rF)r�rr
z) of unique constraints for c��h|]	}|j��
SrHr)r)r�s  rr�z8BaseDatabaseSchemaEditor._alter_field.<locals>.<setcomp>�s��L�L�L�u��
�L�L�Lr)r��type_r
rec��h|]	}|j��
SrHrrss  rr�z8BaseDatabaseSchemaEditor._alter_field.<locals>.<setcomp>�rSr)rer
z) of check constraints for r�Nrqr.r�)rtr`r��r�rdr�rrj�_fk�_check�r�r,)C�setr5r8r�r~rrr`rrr!r��addrBr@r��_field_became_primary_keyr��_delete_unique_sqlrr1�
related_modelr�db_indexrr
r��_delete_index_sql�_delete_check_sql�_rename_field_sqlr>r�r�rename_column_referencesr��_alter_column_collation_sqlrS�_alter_column_type_sqlr}r�r�r�r4�_alter_column_null_sqlr��supports_combined_altersrTr0r��sumr5r[�sql_update_with_default�_delete_primary_key�_unique_should_be_addedrwr�_create_primary_key_sqlrzr�r#�related_objectsr�_create_index_name�_create_check_sqlr7r8))r;r#r+r/rLrNrKrMrJ�fks_droppedrCrDrr�constraint_name�drop_foreign_keys�_old_rel�new_rel�rel_fk_namesr�index_names�
index_namerG�actions�null_actions�post_actions�
old_collation�
new_collation�fragment�
other_actions�needs_database_default�old_default�new_default�four_way_default_alterationrJ�rels_to_update�old_rel�
rel_db_params�rel_type�relr;s)                                         rrIz%BaseDatabaseSchemaEditor._alter_fieldcs����e�e���O�$�:�	B��"�	B�
�#�	B�
�-�-�e�i�6F�5G�UY�-�Z�Z�H��
�#�h�-�-�1�,�,� �j���M�M�M�M��K�(�(�(��$�$�"����
$�
B�
B������!1� 3�4�4�4����T�0�0���@�@�A�A�A�A���	N�Y�%5�	N��9W�9W�Xa�cl�9m�9m�	N�$_�$_�u�{�G^�$_�$_�$_�!�#�5�5��	�(�)�$�E�-� 6� � ���
�#�.�/�/�1�4�4� �j��(�)�)�)�)��K�(�(�(��$�$�"����
$4�
N�
N�����T�4�4�U�O�L�L�M�M�M�M�
�O�$�:�
'��&�@�9�+@�8��!�6�i�&6�
'��h�&�		��	V�&>�i��%S�%S�
V�
V�!��'�#�5�5��)�G�M�,@�+A�t� 6� � �� ,�V�V�G��L�L��!4�!4�W�5J�G�!T�!T�U�U�U�U�V���
	H�i�&6�
	H�	�@R�
	H�V_�Vf�
	H�L�L���8K�L�L�L���0�0��	�(�)��U�\�(�1���K�*�
H�
H�
����T�3�3�E�:�F�F�G�G�G�G���!�]�7�%;�;�;�
�g�@V�;�$_�$_�u�{�G^�$_�$_�$_�!�#�5�5��	�(�)��-� 6� � ���
�#�.�/�/�1�4�4� �j��(�)�)�)�)��K�(�(�(��$�$�"����
$4�
M�
M�����T�3�3�E�?�K�K�L�L�L�L���y�/�/�/��L�L��/�/���0D�i�QZ�\d�e�e�f�f�f��(�
k�
k���c�9�-�-�k��0�0���1E�y�GW�Yb�Yi�j�j�j���������	�>�4�@�@�
��	�>�4�@�@�
��M�)�)��7�7��y�(�Ta�b�b�H��N�N�8�$�$�$�$�
��
!�
!�&*�&A�&A�%��T]�_g�&h�&h�#�H�m��N�N�8�$�$�$����
�.�.�.�"'���>�		\�)�.�		\��0�0��;�;�K��0�0��;�;�K��.�.�y�9�9�
\��{�*�*��'�)-�&����t�=�=�e�Y�PY�Z�Z�[�[�[��>�Y�^�+�+��2�2�5�)�Y�O�O�H��
.��#�#�H�-�-�-�
�!�!�#�#�
4�
�^�
2�I�N� 2�	$��%	�l�%	�.�
1�"�L�0����'�@�
>�W�
>�#�C��M�2�2���V� �I�I�c�N�N�C���O�O�<�=��&�
�
���V�����)�!%�����1E�!F�!F�#&�-�-�������+�
�����0�!%�����1E�!F�!F�"&�/�/�)�2B�"C�"C�#'�4�4��
!�M�
���$0���K�C���L�L��-�%)�_�_�U�[�5I�%J�%J�'*�1�1��������	*�+�
*�
*���V����S�&�)�)�)�)�� �	4��)>�	4��$�$�U�F�3�3�3��'�'�	�9�=�=�	M��L�L��0�0���9I�8J�K�K�L�L�L��"�	L�i�&6�	L�I�<N�	L�W`�Wg�	L��L�L��/�/��y�k�/�J�J�K�K�K����	R��!�!�":�9�i�"P�"P�Q�Q�Q��)�)�)�Y�?�?�	R��L�L��5�5�e�Y�G�G�H�H�H��!�!�":�9�i�"P�"P�Q�Q�Q� .�	*�	*��G�W�#�M�7�7�4�?�7�S�S�M�$�V�,�H�&*�&A�&A��%�w�}�g�m�X�'�'�#�H�m�
�L�L��%�!�_�_�W�-B�-H�-Q�R�R�'��{�)�)�����
�
�
� -�
*�
*���V����S�&�)�)�)�)�
*�
�O�$�:�	b�y�?U�	b��	b�$-�$:�	b�BK�BY�	b��'�	b�
�L�L��,�,�U�I�?_�`�`�a�a�a��	[� ��,�<�
[�
[��(��i�8�8�[�S�Y�=T�[��L�L��!4�!4�S�5F��	�SX�!Y�!Y�Z�Z�Z����!�]�7�%;�;�;�
�g�@V�;�"�5�5�e�k�6J�Y�M]�L^�go�5�p�p�O��L�L��/�/���
�V]�H^�_�_�`�`�`�"�	&�"&�"@�"@��	�S\�cg�"@�"h�"h��K���'������)=�>�>�&�+�+��C�
�L�L��f�%�%�%��?�#�C�	$��O�!�!�#�#�#�#�#�	$�	$rc��|jjjr|���dvrdS|�|j���}|jr|jn|j}||�|j	��|dd�zgfS)z�
        Hook to specialize column null alteration.

        Return a (sql, params) fragment to set a column to null or non-null
        as required by new_field, or None if no changes are required.
        )�	CharField�	TextFieldNrdr��r`r�)
r5r8r�r�rzr��sql_alter_column_null�sql_alter_column_not_nullr[r`)r;r#r+r/rMrGs      rrgz/BaseDatabaseSchemaEditor._alter_column_null_sqlbs���
�O�$�F�
	��+�+�-�-�1K�K�K��F�%�3�3�t��3�O�O�M�09��b�$�,�,�D�Db�C��"�o�o�i�.>�?�?�)�&�1������
rc�~�|�|��}|�|��}|g}|rg}n(|jjjr|�|��}g}|�|j���}|r|jr|j}	n|j	}	n|j
}	|	|�|j��|d|d�z|fS)z�
        Hook to specialize column default alteration.

        Return a (sql, params) fragment to add or drop (depending on the drop
        argument) a default to new_field's column.
        rdr�)r`r�r�)
r�r�r5r8r�r�rzr�� sql_alter_column_no_default_null�sql_alter_column_no_default�sql_alter_column_defaultr[r`)
r;r#r+r/r-r�r�rJrMrGs
          rr4z2BaseDatabaseSchemaEditor._alter_column_default_sqlxs����,�,�Y�7�7���*�*�9�5�5������	��F�F�
�_�
%�
?�	��*�*�;�7�7�G��F�!�/�/�4�?�/�K�K�
��	0��~�
7��;����6����/�C���/�/�)�*:�;�;�%�f�-�"���
�

�

�	
rc�T�|j|�|j��|d�zgfgfS)a�
        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).

        Return a two-tuple of: 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.
        r�)�sql_alter_column_typer[r`)r;r#r+r/rNs     rrfz/BaseDatabaseSchemaEditor._alter_column_type_sql�sG���*�"�o�o�i�.>�?�?�$�.�.���
�
�	
�		
rc��|j|�|j��||r|�|��ndd�zgfS)NrM)r`r�r�)�sql_alter_column_collater[r`r�)r;r#r/rNr}s     rrez4BaseDatabaseSchemaEditor._alter_column_collation_sql�sW���)��/�/�)�*:�;�;� �AN�V�T�.�.�}�=�=�=�TV�-�-�
�

�

�	
rc��|jjjj|jjjjkrI|�|jj|jjjj|jjjj��|�|jj|jjj�|�����|jjj�|�������|�|jj|jjj�|�����|jjj�|�������dS)z*Alter M2Ms to repoint their to= endpoints.N)	r~r�r!r�r!rOr_�m2m_reverse_field_name�m2m_field_name)r;r#r+r/rJs     rrHz,BaseDatabaseSchemaEditor._alter_many_to_many�sQ���!�)�/�8�I�<R�<Z�<`�<i�i�i����	� 6� >�	�@V�@^�@d�@m� )� 6� >� D� M�
O�
O�
O�	
����"�*�
�"�*�0�:�:�9�;[�;[�;]�;]�^�^��"�*�0�:�:�9�;[�;[�;]�;]�^�^�	
�	
�	
�	
����"�*��"�*�0�:�:�9�;S�;S�;U�;U�V�V��"�*�0�:�:�9�;S�;S�;U�;U�V�V�		
�	
�	
�	
�	
rrMc�,�t|��\}}t|g|�Rddi��|��}|jj���pd}|�dd�|���d|��}t
|��|kr|St
|��|dzkr
|d|dz�}|t
|��z
dzdz
}|d|��dd�|��d|��d|��}|d	dks|d	���r
d
|dd�z}|S)z�
        Generate a unique name for an index/unique constraint.

        The name is divided into 3 parts: the table name, the column names,
        and a unique digest and suffix.
        �length���r:�N�rrzD%s���)rr
r5rZ�max_name_lengthr�r�isdigit)	r;�
table_name�column_namesr�r:�hash_suffix_part�
max_lengthrx�other_lengths	         rroz+BaseDatabaseSchemaEditor._create_index_name�s]��)��4�4�
��:�%1�*�%V�|�%V�%V�%V�TU�%V�%V�%V�X^�X^�_���_�(�8�8�:�:�A�c�
�#-�:�:�s�x�x��/E�/E�/E�/E�GW�GW�X�
��z�?�?�j�(�(����� � �:��>�1�1�/�0@��q��0@�A��"�S�)9�%:�%:�:�q�@�1�D���}��}�%�%�%��H�H�\�"�"�=�L�=�1�1�1���
�
��a�=�C���:�a�=�#8�#8�#:�#:����C�R�C��0�J��rc���|�Ft|��dkr|djr|dj}n|jjr|jj}|�"d|jj�|��zSdS)NrrrfrM)rr�r!r5rZr�)r;r#r�r�s    r�_get_index_tablespace_sqlz2BaseDatabaseSchemaEditor._get_index_tablespace_sql�ss��� ��6�{�{�a���F�1�I�$;�� &�q�	� 7�
�
���*�
:� %�� 9�
��$����,�;�;�M�J�J�J�J��rrc��|rd|zSdS)Nz WHERE rMrH)r;�	conditions  r�_index_condition_sqlz-BaseDatabaseSchemaEditor._index_condition_sql�s���	)��y�(�(��rrc��|r|jjjsdStdt	|jj||j�����S)NrMz INCLUDE (%(columns)s))r�)r5r8�supports_covering_indexesrrr!r�r[)r;r#r�s   r�_index_include_sqlz+BaseDatabaseSchemaEditor._index_include_sql�sN���	�d�o�6�P�	��2��$��E�K�0�'�4�?�K�K�
�
�
�	
r)r�rr��usingr��col_suffixesrG�	opclassesr��include�expressionsc
����|pg}|pg}t|d�����j���}
��|||���}d�|D��}|p�j}|jj}��fd�}t|t|�j	��t||||��||r��||||	��nt|||
�j
��|��|
����||�����S)z�
        Return the SQL statement to create the index for one or several fields
        or expressions. `sql` can be specified if the syntax differs from the
        standard (GIS indexes, ...).
        F)�
alias_colsrd)r�c��g|]	}|j��
SrH)r`)r)rs  rrbz>BaseDatabaseSchemaEditor._create_index_sql.<locals>.<listcomp>s��4�4�4�E�5�<�4�4�4rc�L����
�j|i|��������Sr')ror[)�args�kwargsrr;s  ��r�create_index_namezEBaseDatabaseSchemaEditor._create_index_sql.<locals>.create_index_names1����|�.�t�.��?��?�?���?�?�4�(�(�(r)rtrr�r�rKr�r�)r�get_compilerr5r��sql_create_indexr!r�rr	r[r�_index_columnsrrVr�r�)r;r#r�rr�r�r�r�rGr�r�r�r��compilerr�r�r�rtr�s`  `               rrz*BaseDatabaseSchemaEditor._create_index_sqlsJ������2��!�'�R����5�1�1�1�>�>���?�
�
���7�7��v�Ub�7�c�c��4�4�V�4�4�4���7�$�"7����$��	)�	)�	)�	)�	)�	)�����t��/�/��5�'�6�3D�E�E���Q��#�#�E�7�L�)�L�L�L� ���X�t�?O�P�P� ��/�/�	�:�:��+�+�E�7�;�;�

�

�

�
	
rc��t|p|jt|jj|j��|�|�����S�N)rtr)rr�r	r!r�r[)r;r#rrGs    rraz*BaseDatabaseSchemaEditor._delete_index_sql,sG����(�4�(����,�d�o�>�>�����&�&�
�
�
�	
rc�2�t|||j|���S)N)r�)rr[)r;rtr�r�r�s     rr�z'BaseDatabaseSchemaEditor._index_columns3s���u�g�t��\�R�R�R�Rrc����jjr�jjs�jjrgSg}�jjD]+}|�|��|�����,�jjD];}�fd�|D��}|�|�	�|d������<�jj
D]C}|jr|jj
jr)|�|��|�����D|S)z�
        Return a list of all index SQL statements (field indexes,
        index_together, Meta.indexes) for the specified model.
        c�D��g|]}�j�|����SrHr�ras  �rrbz?BaseDatabaseSchemaEditor._model_indexes_sql.<locals>.<listcomp>Br�rr�r�)r!�managed�proxy�swappedrxr}r6�index_togetherrSrrr�r5r8r�r�)r;r#�outputrrr�r�s `     rr�z+BaseDatabaseSchemaEditor._model_indexes_sql6s!���
�{�"�	�e�k�&7�	�5�;�;N�	��I����[�-�	A�	A�E��M�M�$�1�1�%��?�?�@�@�@�@� �;�5�	W�	W�K�L�L�L�L��L�L�L�F��M�M�$�0�0��v�f�0�U�U�V�V�V�V��[�(�	=�	=�E��.�
=���(�D�
=��
�
�e�.�.�u�d�;�;�<�<�<���
rc��g}|�||��r+|�|�||g�����|S)zT
        Return a list of all index SQL statements for the specified field.
        rW)�_field_should_be_indexedrSr)r;r#rr�s    rr6z+BaseDatabaseSchemaEditor._field_indexes_sqlMsN�����(�(���6�6�	I��M�M�$�0�0���w�0�G�G�H�H�H��
rc�T�|���\}}}}|���\}}}}	gd�}
|
D].}|�|d��|	�|d���/|�|j��|�|j��kp|||f|||	fkS)N)r��	db_column�editable�error_messages�	help_text�limit_choices_to�	on_delete�related_name�related_query_name�
validators�verbose_name)�deconstruct�popr[r`)r;r+r/r:�old_path�old_args�
old_kwargs�new_path�new_args�
new_kwargs�non_database_attrs�attrs            rrGz1BaseDatabaseSchemaEditor._field_should_be_alteredVs���,5�,A�,A�,C�,C�)��8�X�z�,5�,A�,A�,C�,C�)��8�X�z�


�

�

��'�	'�	'�D��N�N�4��&�&�&��N�N�4��&�&�&�&��O�O�I�,�-�-�����AQ�1R�1R�R�
Q�
�x��,��8�Z�0P�P�	
rc� �|jo|jSr')r`r��r;r#rs   rr�z1BaseDatabaseSchemaEditor._field_should_be_indexedss���~�2�e�l�"2�2rc� �|jo|jSr'�r�r;r+r/s   rr]z2BaseDatabaseSchemaEditor._field_became_primary_keyvs���(�(�B�Y�-B�Brc�L�|jr|jp|jo|jo|jSr')r�rr�s   rrlz0BaseDatabaseSchemaEditor._unique_should_be_addedys6���$�$�9��)9�
��!�T�)�*?�&?�T�I�DT�	
rc��|j|�|��|�|j��|�|j��|d�zS)N)rt�
old_column�
new_columnr�)�sql_rename_columnr[r`)r;rtr+r/rNs     rrcz*BaseDatabaseSchemaEditor._rename_field_sql~sR���%��_�_�U�+�+��/�/�)�*:�;�;��/�/�)�*:�;�;��	)
�)
�
�	
rc	���t|jj|j��}|�|||��}t|jj|jg|j��}t|jjjj|j��}t|jjjj|jjg|j��}|j	j
���}	t|j
||||||	���S)N)rtrr`rhrir+)r	r!r�r[r1rr`�target_fieldr#r5rZr2r�
sql_create_fk)
r;r#rr�rtrr`rhrir+s
          rr�z'BaseDatabaseSchemaEditor._create_fk_sql�s����e�k�*�D�O�<�<���'�'��u�f�=�=�����-���~�t��O�O����+�1�7�@�$�/�R�R���E�.�4�:�C�e�FX�F_�E`�bf�bq�r�r�	��_�(�7�7�9�9�
���������!�
�
�
�	
rc����fd�}t|jj|jgt	|jjjj��d|jjg||��S)Nc�D�����j|i|����Sr'�r[ro�r�r�r;s  �r�create_fk_namezDBaseDatabaseSchemaEditor._fk_constraint_name.<locals>.create_fk_name��(����?�?�#:�4�#:�D�#K�F�#K�#K�L�L�Lrr)rr!r�r`rr�r#)r;r#rr�r�s`    rr1z,BaseDatabaseSchemaEditor._fk_constraint_name�sr���	M�	M�	M�	M�	M���K� �
�\�N��U�/�5�;�D�E�E�a�H�
�
�
&�'���

�
�	
rc�:�|�|j||��Sr')r�
sql_delete_fk�r;r#rs   rr@z'BaseDatabaseSchemaEditor._delete_fk_sql�����*�*�4�+=�u�d�K�K�Krc�V�|�dS|tjkrdS|tjkrdSdS)NrMz DEFERRABLE INITIALLY DEFERREDz DEFERRABLE INITIALLY IMMEDIATE)r�DEFERRED�	IMMEDIATE)r;r+s  r�_deferrable_constraint_sqlz3BaseDatabaseSchemaEditor._deferrable_constraint_sql�s=�����2���,�,�,�3�3���-�-�-�4�4�.�-rc�v�|r|jjjsdS|s|s|r9|�||||||���}|r|j�|��dS|jd�t|j	|����|�
|��d�z}	|j|�	|��|	d�zS)N)rr�r�r�rq)r�r+�rrp)r5r8�&supports_deferrable_unique_constraintsrwr>rS�sql_unique_constraintr�rUr[r��sql_constraint)
r;r#r�rr�r+r�r�rGrps
          r�_unique_sqlz$BaseDatabaseSchemaEditor._unique_sql�s���

�	���(�O�	��4��
	��
	�9�
	��)�)����#��#�
*���C��
.��!�(�(��-�-�-��4��/��y�y��T�_�f�!=�!=�>�>��9�9�*�E�E�3
�3
�
�
��"��O�O�D�)�)�$�&
�&
�
�	
rc�&��|r�jjjr&|r�jjjr|r�jjjsdS�fd�}t|jj�j��}	|�t|jj|d|��}n��|��}��
|	|d|���}|s|s|r�j}
n�j}
t|
|	||��|����|����||�����S)Nc�D�����j|i|����Sr'r�r�s  �r�create_unique_namezGBaseDatabaseSchemaEditor._create_unique_sql.<locals>.create_unique_name�r�r�_uniqrH)r�r�)rtrr�r�r+r�)r5r8r��supports_partial_indexesr�r	r!r�r[rr��sql_create_unique_index�sql_create_uniquerr�r�r�)r;r#r�rr�r+r�r�rrtrGs`          rrwz+BaseDatabaseSchemaEditor._create_unique_sql�sb����	��O�,�S�	�
�	�
 $��7�P�	��
	�"�_�5�O�
	��4�	M�	M�	M�	M�	M��e�k�*�D�O�<�<���<��U�[�1�7�G�EW�X�X�D�D��?�?�4�(�(�D��%�%�e�W�2�QZ�%�[�[���	)��	)�9�	)��.�C�C��(�C�������/�/�	�:�:��6�6�z�B�B��+�+�E�7�;�;�
�
�
�	
rc���|r|jjjr&|r|jjjr|r|jjjsdS|s|s|r|j}n|j}|�|||��Sr')r5r8r�rr�r�r�r)r;r#rr�r+r�r�rGs        rr^z+BaseDatabaseSchemaEditor._delete_unique_sql�s����	��O�,�S�	�
�	�
 $��7�P�	��
	�"�_�5�O�
	��4��	)��	)�9�	)��'�C�C��(�C��*�*�3��t�<�<�<rc�V�|j|�|��|jd|izd�zS)Nrer�)rr[r{)r;rres   r�
_check_sqlz#BaseDatabaseSchemaEditor._check_sqls;���"��O�O�D�)�)��3�w��6F�F�&
�&
�
�	
rc��t|jt|jj|j��|�|��|���S)N)rtrre)r�sql_create_checkr	r!r�r[)r;r#rres    rrpz*BaseDatabaseSchemaEditor._create_check_sql
sE����!����,�d�o�>�>�����&�&��	
�
�
�	
rc�:�|�|j||��Sr')r�sql_delete_checkr�s   rrbz*BaseDatabaseSchemaEditor._delete_check_sqls���*�*�4�+@�%��N�N�Nrc��t|t|jj|j��|�|�����Sr�)rr	r!r�r[)r;�templater#rs    rrz/BaseDatabaseSchemaEditor._delete_constraint_sqls?�������,�d�o�>�>�����&�&�
�
�
�	
rc
���|��fd�|D��}�j���5}
�jj�|
|jj��}ddd��n#1swxYwYg}|���D]�\}
}|�||dkrq|�
|d|kr�"|�
|d|kr�1|�
|d|kr�@|�
|d|kr�O|�	|ds�Z|�
|d	|kr�i|	r|
|	vr|�|
����|S)
z@Return all constraint names matching the columns and conditions.Nc�N��g|]!}�jj�|����"SrH)r5�
introspection�identifier_converter)r)rr;s  �rrbz>BaseDatabaseSchemaEditor._constraint_names.<locals>.<listcomp>$s<���������-�B�B�4�H�H���rr�r�rr�rer?r�)r5rWr�get_constraintsr!r��itemsrS)r;r#r�r�rr�r?rerUr
rWr��resultr�infodicts`              rrz*BaseDatabaseSchemaEditor._constraint_namess�����#�����(����L��_�
#�
#�
%�
%�	f���/�7�G�G��PU�P[�Pd�e�e�K�	f�	f�	f�	f�	f�	f�	f�	f�	f�	f�	f����	f�	f�	f�	f���)�/�/�1�1�	(�	(�N�D�(��#�|�x�	�7J�'J�'J��%�(�8�*<��*F�*F���*�x�
�/F�+�/U�/U���$��'�):�e�)C�)C���$��'�):�e�)C�)C���*�8�M�3J�*���$��&�)9�U�)B�)B���(�$�g�"5�"5��M�M�$�'�'�'���
s�+A"�"A&�)A&c��|�|d���}|r?t|��dkr,tdt|���d|jj�����|D]+}|�|�||�����,dS)NTr�rrz) of PK constraints for )rrrr!r�rB�_delete_primary_key_sql)r;r#rJrrrs     rrkz,BaseDatabaseSchemaEditor._delete_primary_key=s����1�1�%�T�1�J�J���	�c�*�+�+�q�0�0��*��$�%�%�%�%���$�$����
� 0�	O�	O�O��L�L��5�5�e�_�M�M�N�N�N�N�	O�	Orc�&�t|jt|jj|j��|�|�|jj|jgd�����t|jj|jg|j�����S)N�_pkrZ)rtrr�)	r�
sql_create_pkr	r!r�r[ror`rr�s   rrmz0BaseDatabaseSchemaEditor._create_primary_key_sqlGs���������,�d�o�>�>�����'�'���(<�u�|�n�UZ�'�[�[����E�K�0�5�<�.�$�/�R�R�

�
�
�	
rc�:�|�|j||��Sr')r�
sql_delete_pkr�s   rrz0BaseDatabaseSchemaEditor._delete_primary_key_sqlQr�rc�2�d|�|��zS)Nz	 COLLATE )r[)r;r�s  rr�z%BaseDatabaseSchemaEditor._collate_sqlTs���T�_�_�Y�7�7�7�7rc��|j|�|��d�|��d�z}|�|��dS)N�,)�	procedure�param_types)�sql_delete_procedurer[r�rB)r;�procedure_namer%rGs    r�remove_procedurez)BaseDatabaseSchemaEditor.remove_procedureWsQ���'�����8�8��8�8�K�0�0�+
�+
�
��	
���S�����r)FT)rH)F)rMr')NNNN)NNNNN)NNNNNNNN)h�__name__�
__module__�__qualname__�__doc__r�rr%r�r3r5r�r�r�r�r�r�r�rAr�rjr�r{�sql_delete_constraintrr
rrr�r�r�r0r�r�rr�rr r&r<r@rCrBr[r�ryr�r�r�r��staticmethodr�r�rVr�r�r�r�r�r�r�rr�r!r(r<rErOrIrgr4rfrerHror�r�r�rrar�r�r6rGr�r]rlrcr�r1r@r�rrwr^rrprbrrrkrmrr�r(rHrrr3r3-s���������A��J��V��5��T��:��C��C�� F��P��"H��'B�$�S��N��^��f��@��.��L��9�N�X��,��j��-��	@�� ��"&��)�M�j��o��,��]�M�)�M�9��U�U�U�U����A�A�A�,�,�,�,�.4�4�4�7�7�7�v:�:�:�:�x������
�
�
��������\��,W�W�W�$�$�$�>�>�>�".�.�.� 	A�	A�	A�4�4�4�+�+�+����B�B�B� V�V�V�*S�S�S� 
H�
H�
H����7$�7$�7$�r.�.�.�<)@�)@�)@�)@�X;@�}$�}$�}$�}$�~���,#
�#
�#
�#
�J
�
�
�*
�
�
�
�
�
�*����:�������

�
�
�26�D��SU�(,�2�4�SU�$(�$�D�%
�%
�%
�%
�%
�N
�
�
�
�S�S�S����.���
�
�
�:3�3�3�C�C�C�
�
�
�

�
�
�
�
�
�"
�
�
�L�L�L�5�5�5�?C� $�
�
�
�
�BEI� $�#
�#
�#
�#
�LEI��=�=�=�=�&
�
�
�
�
�
�O�O�O�
�
�
�BF�DH�:>�����<O�O�O�O�
�
�
�L�L�L�8�8�8������rr3)�loggingr�!django.db.backends.ddl_referencesrrrrrr	�django.db.backends.utilsr
r�django.db.modelsrr
�django.db.models.sqlr�django.db.transactionrr�django.utilsr�	getLoggerrPrr$r1r3rHrr�<module>r7s^����������������������������D�C�C�C�C�C�C�C�.�.�.�.�.�.�.�.�&�&�&�&�&�&�D�D�D�D�D�D�D�D�!�!�!�!�!�!�	��	�6�	7�	7��
1�
1�
1� U�U�U����o�o�o�o�o�o�o�o�o�or

Youez - 2016 - github.com/yon3zu
LinuXploit