o
    /h<                     @   sl   d Z ddlZddlmZ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S )z
Recreates the public schema for current database (PostgreSQL only).
Useful for Docker environments where you need to reset database
schema while there are active connections.
    N)BaseCommandCommandError)DEFAULT_DB_ALIAS)connections)settings)POSTGRESQL_ENGINES)RemovedInNextVersionWarningc                       s,   e Zd ZdZdZ fddZdd Z  ZS )Commandz&`reset_schema` command implementation.z-Recreates the public schema for this project.c                    sf   t  | |jddddddd |jdd	d
dtdd |jdtdt d |jddd
dddd d S )Nz	--noinputz
--no-inputstore_falseinteractiveTz:Tells Django to NOT prompt the user for input of any kind.)actiondestdefaulthelpz-Rz--routerstorerouterzBUse this router-database instead of the one defined in settings.pyz
--databasez>Nominates a database to run command for. Defaults to the "%s".)r   r   z-Sz--schemaschemapublicz$Drop this schema instead of "public")superadd_argumentsadd_argumentr   )selfparser	__class__ m/var/www/html/env_mimamsha/lib/python3.10/site-packages/django_extensions/management/commands/reset_schema.pyr      s@   
zCommand.add_argumentsc           
      O   s   |d }|d t krtjdtdd |d }tj|}|d u r&td| |d}|tvr3td|d	 }|d
 }|d rHt	d
||}nd}|dkrTtd d S t|  }	|	d
| |	d
| W d    d S 1 svw   Y  d S )Ndatabaser   z2--router is deprecated. You should use --database.   )
stacklevelzUnknown database %sENGINEz8This command can be used only with PostgreSQL databases.NAMEr   r   z
You have requested a database schema reset.
This will IRREVERSIBLY DESTROY ALL data
in the "{}" schema of database "{}".
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yeszReset cancelled.zDROP SCHEMA {} CASCADEzCREATE SCHEMA {})r   warningswarnr   r   	DATABASESgetr   r   inputformatprintr   cursorexecute)
r   argsoptionsr   dbinfoenginedatabase_namer   confirmr*   r   r   r   handle9   s>   

"zCommand.handle)__name__
__module____qualname____doc__r   r   r2   __classcell__r   r   r   r   r	      s
    !r	   )r6   r#   django.core.managementr   r   	django.dbr   r   django.confr   django_extensions.settingsr   #django_extensions.utils.deprecationr   r	   r   r   r   r   <module>   s   