o
    ѷ6i#
                     @  s   d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dl
mZ d d	lmZ d d
lmZ G dd deZd Zddd ej D jddZde d  ZdZdS )    )annotationsN)Any)settings)InvalidCacheBackendError)caches)BaseCommand)CommandError)
MySQLCache)collapse_spacesc                   @  s6   e Zd ZdZedZdddZdddZdddZdS )Commandz
<app_name>z;
        Outputs a migration that will create a table.
    parserargparse.ArgumentParserreturnNonec                 C  s   |j ddddd d S )Naliases*z5Specify the cache alias(es) to create migrations for.)metavarnargshelp)add_argument)selfr    r   {/var/www/hoanhtaovolam_webdjango/env/lib/python3.10/site-packages/django_mysql/management/commands/mysql_cache_migration.pyadd_arguments   s   
zCommand.add_argumentsargsr   r   	list[str]optionsc             	   O  s   |st tj}t }|D ]$}zt| }W n ty#   td|dw t|ts*q|	|j
 q|s;| jd d S | |}| j| d S )NzCache z does not existz!No MySQLCache instances in CACHES)listr   CACHESsetr   r   r   
isinstancer	   add_tablestderrwriterender_migrationstdout)r   r   r   r   tablesaliascache	migrationr   r   r   handle!   s"   


zCommand.handler'   set[str]strc                 C  s6   t g}|D ]}|td| q|t d|S )N{{ table }} )headerappendtable_operationreplacefooterjoin)r   r'   outtabler   r   r   r%   8   s
   

zCommand.render_migrationN)r   r   r   r   )r   r   r   r   r   r   r   r   )r'   r,   r   r-   )	__name__
__module____qualname__r   r
   r   r   r+   r%   r   r   r   r   r      s    

r   a  
from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        # Add a dependency in here on an existing migration in the app you
        # put this migration in, for example:
        # ('myapp', '0001_initial'),
    ]

    operations = [

c                 c  s    | ]}d | V  qdS )z            Nr   ).0liner   r   r   	<genexpr>R   s    
r>   r.   )
table_namez,
        migrations.RunSQL(
            """
zE
            """,
            "DROP TABLE `{{ table }}`",
        ),
z
    ]
)
__future__r   argparsetypingr   django.confr   django.core.cacher   r   django.core.managementr   r   django_mysql.cacher	   django_mysql.utilsr
   r   stripr0   r5   create_table_sql
splitlinesformatrstripr2   r4   r   r   r   r   <module>   s6    3
