
    Vh0                     n    d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
mZmZmZmZmZ  G d de      Zy)	    )settings)caches)BaseDatabaseCache)BaseCommandCommandError)DEFAULT_DB_ALIASDatabaseErrorconnectionsmodelsroutertransactionc                   &    e Zd ZdZg Zd Zd Zd Zy)Commandz7Creates the tables needed to use the SQL cache backend.c                     |j                  dddd       |j                  dt        t        t              d       |j                  d	d
d       y )Nargs
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.)defaultchoicesr   z	--dry-run
store_truezADoes not create the table, just prints the SQL that would be run.)actionr   )add_argumentr   tupler
   )selfparsers     `/home/dcms/DCMS/lib/python3.12/site-packages/django/core/management/commands/createcachetable.pyadd_argumentszCommand.add_arguments   si       	 	
 	$+&=	 	 	
 	T 	 	
    c                     |d   }|d   | _         |d   }|r|D ]  }| j                  |||        y t        j                  D ]9  }t        |   }t        |t              s| j                  ||j                  |       ; y )Ndatabase	verbositydry_run)r$   create_tabler   CACHESr   
isinstancer   _table)r   
tablenamesoptionsdbr%   	tablenamecache_aliascaches           r   handlezCommand.handle+   s    Z  -)$' :	!!"i9:  ( A{+e%67%%b%,,@Ar!   c                    t        |i       }t        j                  ||j                        sy t        |   }||j
                  j                         v r.| j                  dkD  r| j                  j                  d|z         y t        j                  dddd      t        j                  d      t        j                  d	d
      f}g }g }|j                  j                  }	|D ]  }
 |	|
j                         |
j#                  |      d|
j$                  sdndz  g}|
j&                  r|j)                  d       n|
j*                  r|j)                  d       |
j,                  rY|
j*                  rdnd}|j)                  d|d |	|d|
j                         d |	|      d |	|
j                         d	       |j)                  dj/                  |              d |	|      z  g}t1        |      D ].  \  }}|j)                  d||t3        |      dz
  k  rdnd       0 |j)                  d       dj/                  |      }|r>| j                  j                  |       |D ]  }| j                  j                  |        y t5        j6                  ||j8                  j:                        5  |j=                         5 }	 |j?                  |       |D ]  }|j?                  |        	 d d d        d d d        | j                  dkD  r| j                  j                  d"|z         y y # t@        $ r}tC        d|d |d!      d }~ww xY w# 1 sw Y   cxY w# 1 sw Y   gxY w)#Nr   z Cache table '%s' already exists.	cache_key   T)name
max_lengthuniqueprimary_keyvalue)r4   expires)r4   db_index)
connectionz%sNULLzNOT  zPRIMARY KEYUNIQUEzUNIQUE zCREATE zINDEX _z ON z (z); zCREATE TABLE %s (z       ,
)using	savepointzCache table 'z'' could not be created.
The error was: .zCache table '%s' created.)"r   r   allow_migrate_modelcache_model_classr
   introspectiontable_namesr$   stdoutwriter   	CharField	TextFieldDateTimeFieldops
quote_namer4   db_typenullr7   appendr6   r:   join	enumeratelenr   atomicfeaturescan_rollback_ddlcursorexecuter	   r   )r   r#   r-   r%   r/   r;   fieldstable_outputindex_outputqnffield_outputr6   full_statementiline	statementcurses                      r   r&   zCommand.create_table9   s&   !)R0))(E4K4KL *

00<<>>~~!!!"Dy"PQ  S4 '*  i$?
 ^^&& 	8A166
		Z	0!&&Fb9L
 }}##M2##H-zz&'hhB## i899166
  67+	8, .9=> . 	GAt!!"1s</@1/D+DC"$LM	 	d#>2KKn-) -	!!),-j&9&9&J&J
 	, ""$ 	,LL0 ". ,ILL+,	,	, >>AKK9IEF  % &$a) 	, 	,	, 	,sH   2MML.M/M.	M7M		MMM	MM&N)__name__
__module____qualname__r   requires_system_checksr    r0   r&    r!   r   r   r      s    DD
.AJGr!   r   N)django.confr   django.core.cacher   django.core.cache.backends.dbr   django.core.management.baser   r   	django.dbr   r	   r
   r   r   r   r   rl   r!   r   <module>rr      s+      $ ; A tGk tGr!   