https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/django/db/backends/sqlite3/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/django/db/backends/sqlite3/__pycache__/schema.cpython-310.pyc
o

3�aQ�@s|ddlZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZdd	lmZGd
d�de�ZdS)�N)�Decimal)�Apps)�NotSupportedError)�BaseDatabaseSchemaEditor)�	Statement)�strip_quotes)�UniqueConstraint)�atomiccs�eZdZdZdZdZdZdZ�fdd�Z�fdd	�Z	d
d�Z
d&d
d�Zd'�fdd�	Zd(�fdd�	Z
d)dd�Zd'�fdd�	Zdd�Zdd�Z	d(dd�Zdd�Z�fd d!�Z�fd"d#�Zd$d%�Z�ZS)*�DatabaseSchemaEditorzDROP TABLE %(table)sNzEREFERENCES %(to_table)s (%(to_column)s) DEFERRABLE INITIALLY DEFERREDz7CREATE UNIQUE INDEX %(name)s ON %(table)s (%(columns)s)zDROP INDEX %(name)scs|j��s	td��t���S)Nz�SQLite schema editor cannot be used while foreign key constraint checks are enabled. Make sure to disable them before entering a transaction.atomic() context because SQLite does not support disabling them in the middle of a multi-statement transaction.)�
connection�disable_constraint_checkingr�super�	__enter__��self��	__class__��C/usr/lib/python3/dist-packages/django/db/backends/sqlite3/schema.pyrs

�
zDatabaseSchemaEditor.__enter__cs(|j��t��|||�|j��dS�N)r�check_constraintsr
�__exit__�enable_constraint_checking)r�exc_type�	exc_value�	tracebackrrrr"s
zDatabaseSchemaEditor.__exit__cCs�zddl}|�|�}WntyYn
|jyYnwt|t�r)tt|��St|tt	tf�r5t|�St|t�rBd|�
dd�S|durHdSt|ttt
f�rVd|��Std|t|�f��)Nrz'%s'�'z''�NULLzX'%s'z*Cannot quote parameter value %r of type %s)�sqlite3�adapt�ImportError�ProgrammingError�
isinstance�bool�str�intr�float�replace�bytes�	bytearray�
memoryview�hex�
ValueError�type)r�valuerrrr�quote_value's&�

z DatabaseSchemaEditor.quote_valueFc
Cs�|j���G}|jj�|�D]6}|r|j|krq
|jj�||j�}|��D]}|d\}}	||krB|dus8|	|krBWd�dSq$q
Wd�dS1sOwYdS)a
        Return whether or not the provided table name is referenced by another
        one. If `column_name` is specified, only references pointing to that
        column are considered. If `ignore_self` is True, self-referential
        constraints are ignored.
        �foreign_keyNTF)r�cursor�
introspection�get_table_list�name�_get_foreign_key_constraints�values)
r�
table_name�column_name�ignore_selfr1�other_table�constraints�
constraint�constraint_table�constraint_columnrrr�_is_referenced_by_fk_constraintCs$���
�
�
z4DatabaseSchemaEditor._is_referenced_by_fk_constraintTcsh|jjjs*|r*|�|�r*|jjrtd|��|j��t��|||�|j�	�dSt��|||�dS)Nz�Renaming the %r table while in a transaction is not supported on SQLite < 3.26 because it would break referential integrity. Try adding `atomic = False` to the Migration class.)
r�features�!supports_atomic_references_renamer?�in_atomic_blockrrr
�alter_db_tabler)r�model�old_db_table�new_db_table�disable_constraintsrrrrCVs
���
z#DatabaseSchemaEditor.alter_db_tablec	s�|�||�sdS|j}|jj}|��\}}|j|kr�|jjjs�|j||dd�r�|jj	r5t
d|jj|f��t|jj��bt
�j||||d�|j���C}	|	�d���d}
|	�d�d|}|��d	}||}
||}|	�d
|
|f�|	�d|
d	�|	�d�|	�d
�Wd�n1s�wYWd�n1s�wY|j���}	|	�d�Wd�dS1s�wYdSt
�j||||d�dS)NT)r9z�Renaming the %r.%r column while in a transaction is not supported on SQLite < 3.26 because it would break referential integrity. Try adding `atomic = False` to the Migration class.)�strictzPRAGMA schema_versionrzPRAGMA writable_schema = 1z REFERENCES "%s" ("%%s") �z3UPDATE sqlite_master SET sql = replace(sql, %s, %s)zPRAGMA schema_version = %dzPRAGMA writable_schema = 0zPRAGMA integrity_check�VACUUM)�_field_should_be_alteredr4�_meta�db_table�get_attname_columnrr@rAr?rBrr	�aliasr
�alter_fieldr1�execute�fetchone)rrD�	old_field�	new_fieldrH�old_field_namer7�_�old_column_namer1�schema_version�references_template�new_column_name�search�replacementrrrrPesF
��
�

���"�z DatabaseSchemaEditor.alter_fieldc	sH�fdd���fdd��jjD�}�fdd��jjD�}i�d}t|dd�s0|rMt|d	dd�rMt|���D]\}}	|	jrLd|	_|	}|	jrL||=||	j=q6|re|||j<|j	se|j
re����|��||j<|r�|\}
}|�
|
jd�|�
|
jd�|||j<|
jr�|js�d
��|
j�����|��d�}|||j<n	��|
j�||j<|j�|
j<�r�|�j=|�j=�j	rĈjjjjrĈ��jj�St�}
�fdd
��jjD�}�fdd
��jjD�}�jj}�r�fdd
�|D�}t�jj�}t�|�}�jj�jj|||||
d�}tdd|�}||d<�j|d<t�jj�j|�t�|�}�jjdt �jj�|||||
d�}tdd|�}||d<�j|d<td�jj�j|�}��!|���"d��|jj�d�#�fdd�|D��d�#|�$�����jj�f��j�dd��j%||jj�jjdd��j&D]}��"|��q�g�_&|�r�d|_dSdS)a|
        Shortcut to transform a model from old_model into new_model

        This follows the correct procedure to perform non-rename or column
        addition operations based on SQLite's documentation

        https://www.sqlite.org/lang_altertable.html#caution

        The essential steps are:
          1. Create a table with the updated definition called "new__app_model"
          2. Copy the data from the existing "app_model" table to the new table
          3. Drop the "app_model" table
          4. Rename the "new__app_model" table to "app_model"
          5. Restore any index of the previous "app_model" table.
        cs|jo|jj�uSr)�is_relation�remote_fieldrD)�f)rDrr�is_self_referential�sz?DatabaseSchemaEditor._remake_table.<locals>.is_self_referentialcs$i|]}|j�|�r|��n|�qSr)r4�clone��.0r_)r`rr�
<dictcomp>�s��z6DatabaseSchemaEditor._remake_table.<locals>.<dictcomp>csi|]
}|j��|j��qSr)�column�
quote_namerbrrrrd�sN�primary_keyFrIzcoalesce(%(col)s, %(default)s))�col�defaultc�g|]}�fdd�|D��qS)c�g|]}��||��qSr��get�rc�n��rename_mappingrr�
<listcomp>���ADatabaseSchemaEditor._remake_table.<locals>.<listcomp>.<listcomp>r)rc�uniquerprrrr����z6DatabaseSchemaEditor._remake_table.<locals>.<listcomp>crj)crkrrlrnrprrrr�rsrtr�rc�indexrprrrr�rvcsg|]
}�j|jvr|�qSr)r4�fieldsrw��delete_fieldrrrr�s
�)�	app_labelrM�unique_together�index_together�indexesr;�apps�Metar�
__module__znew__%szNew%s�%INSERT INTO %s (%s) SELECT %s FROM %s�, c3s�|]}��|�VqdSr)rf)rc�xrrr�	<genexpr>s�z5DatabaseSchemaEditor._remake_table.<locals>.<genexpr>)�handle_autom2m)rGT)'rL�local_concrete_fields�getattr�list�itemsrg�auto_createdrer4�many_to_many�concreter/�effective_default�pop�nullrfr^�through�delete_modelrr}r~rr;�copy�deepcopyr|rMr-r��object_name�	__bases__r�create_modelrQ�joinr6rC�deferred_sql)rrD�create_fieldr{rP�body�mapping�restore_pk_fieldr4�fieldrSrT�case_sqlr�r}r~rr;�	body_copy�
meta_contents�meta�	new_model�sqlr)r{r`rDrqrr�
_remake_table�s�
����

�

�
�
�
�
�	

�	

��

�z"DatabaseSchemaEditor._remake_tablecsj|r
t��|�dS|�|jd|�|jj�i�t|j�D]}t	|t
�r2|�|jj�r2|j�|�qdS)N�table)
r
r�rQ�sql_delete_tablerfrLrMr�r�r"r�references_table�remove)rrDr�r�rrrr�5s���z!DatabaseSchemaEditor.delete_modelcCs2|jr|jjjjr|�|jj�S|j||d�dS)z�
        Create a field on a model. Usually involves adding a column, but may
        involve adding a table instead (for M2M fields).
        )r�N)r�r^r�rLr�r�r��rrDr�rrr�	add_fieldBszDatabaseSchemaEditor.add_fieldcCsT|jr|jjjjr|�|jj�dSdS|j|jd�ddur!dS|j||d�dS)z�
        Remove a field from a model. Usually involves deleting a column,
        but for M2Ms may involve deleting a table.
        )rr-Nrz)	r�r^r�rLr�r��
db_parametersrr�r�rrr�remove_fieldLs�z!DatabaseSchemaEditor.remove_fieldc	Cs:|jjjr0|j|jkr0|�||�|�||�kr0|jr|js0|jr#|js0|�|�|j	j
|||��S|j|||fd�|jr�||kr�t
�}	|jj	}
|
jD]&}|j|krRqJ|jsb|j|jkra|	�|j�qJ|jrp|jj	jrp|	�|j�qJ|jr�|
jD]}|j|krqw|jjj	jr�|	�|jj�qw|	D]}
|�|
�q�dSdSdS)z3Perform a "physical" (non-ManyToMany) field update.�rPN)rr@�can_alter_table_rename_columnre�
column_sqlr^�
db_constraintrQ�_rename_field_sqlrLrMr�ru�setrD�related_objects�
related_modelr��
field_namer4�addrgr�r�)rrDrSrT�old_type�new_type�
old_db_params�
new_db_paramsrH�related_models�optsr^r�r�rrr�_alter_field^sJ
����

��

��z!DatabaseSchemaEditor._alter_fieldcCs�|jjjj|jjjjkr)|j|jj|jjj�|���|jjj�|���fd�dS|�|jj�|�d|�	|jjjj�d�
d|��|��g�d�
d|��|��g�|�	|jjjj�f�|�
|jj�dS)z*Alter M2Ms to repoint their to= endpoints.r�Nr�r��id)r^r�rLrMr��	get_field�m2m_reverse_field_namer�rQrfr��m2m_column_name�m2m_reverse_namer�)rrDrSrTrHrrr�_alter_many_to_many�s0��	���z(DatabaseSchemaEditor._alter_many_to_manyc�0t|t�r|jrt��||�dS|�|�dSr)r"r�	conditionr
�add_constraintr��rrDr<rrrr���z#DatabaseSchemaEditor.add_constraintcr�r)r"rr�r
�remove_constraintr�r�rrrr��r�z&DatabaseSchemaEditor.remove_constraintcCsd|S)Nz	 COLLATE r)r�	collationrrr�_collate_sql�sz!DatabaseSchemaEditor._collate_sql)NF)T)F)NNN)�__name__r��__qualname__r��
sql_create_fk�sql_create_inline_fk�sql_create_unique�sql_delete_uniquerrr/r?rCrPr�r�r�r�r�r�r�r�r��
__classcell__rrrrr

s.


)(


�$#r
)r��decimalr�django.apps.registryr�	django.dbr�django.db.backends.base.schemar�!django.db.backends.ddl_referencesr�django.db.backends.utilsr�django.db.modelsr�django.db.transactionr	r
rrrr�<module>s

https://t.me/RX1948 - 2025