/usr/local/lib/python3.9/site-packages/django/core/management/commands/__pycache__
a Ӱ�h � @ sh d dl mZ d dlmZ d dlmZ d dlmZmZ d dl m Z mZmZm Z mZmZ G dd� de�ZdS ) � )�settings)�caches)�BaseDatabaseCache)�BaseCommand�CommandError)�DEFAULT_DB_ALIAS� DatabaseError�connections�models�router�transactionc @ s, e Zd ZdZg Zdd� Zdd� Zdd� ZdS ) �Commandz7Creates the tables needed to use the SQL cache backend.c C s6 |j ddddd� |j dtdd� |j d d dd� d S ) N�argsZ table_name�*zNOptional table names. Otherwise, settings.CACHES is used to find cache tables.)�metavar�nargs�helpz --databasezgNominates a database onto which the cache tables will be installed. Defaults to the "default" database.)�defaultr z --dry-run� store_truezADoes not create the table, just prints the SQL that would be run.)�actionr )�add_argumentr )�self�parser� r �Z/usr/local/lib/python3.9/site-packages/django/core/management/commands/createcachetable.py� add_arguments s � ��zCommand.add_argumentsc O sj |d }|d | _ |d }|r8|D ]}| �|||� q"n.tjD ]&}t| }t|t�r>| �||j|� q>d S )N�database� verbosity�dry_run)r �create_tabler ZCACHESr � isinstancer �_table)r Z tablenames�options�dbr � tablenameZcache_alias�cacher r r �handle* s zCommand.handlec C s� t |i �}t�||j�sd S t| }||j�� v rP| jdkrL| j� d| � d S t jddddd�t jdd�t j d dd �f}g }g }|jj} |D ]�} | | j�| j|d�d| js�d nd g}| jr�|�d� n| jr�|�d� | j�r| jr�dnd}|�d|| d|| jf �| |�| | j�f � |�d�|�� q�d| |� g} t|�D ]2\}}| �d||t|�d k �rldndf � �qF| �d� d�| �} |�r�| j� | � |D ]}| j� |� �q�d S tj||jjd��� |�� �l}z|�| � W n6 t �y } zt!d||f ��W Y d }~n d }~0 0 |D ]}|�|� �q$W d � n1 �sL0 Y W d � n1 �sl0 Y | jdk�r�| j� d| � d S )Nr z Cache table '%s' already exists.� cache_key� T)�name� max_length�unique�primary_key�value)r) �expires)r) �db_index)� connectionz%sNULLzNOT � zPRIMARY KEYZUNIQUEzUNIQUE zCREATE %sINDEX %s ON %s (%s);z%s_%s� zCREATE TABLE %s (z %s%s� �,z);� )�usingZ savepointz9Cache table '%s' could not be created. The error was: %s.zCache table '%s' created.)"r r Zallow_migrate_modelZcache_model_classr Z introspectionZtable_namesr �stdout�writer Z CharFieldZ TextFieldZ DateTimeField�opsZ quote_namer) Zdb_type�nullr, �appendr+ r/ �join� enumerate�lenr Zatomic�featuresZcan_rollback_ddl�cursor�executer r )r r r$ r r% r0 �fieldsZtable_outputZindex_output�qn�fZfield_outputr+ Zfull_statement�i�lineZ statementZcurs�er r r r 8 s� � � � ��� � � ��NzCommand.create_tableN)�__name__� __module__�__qualname__r Zrequires_system_checksr r&