a
    8Xh+                     @   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
--databasezGNominates a database to run command for. Defaults to the "%s" database.)r   r   z-Sz--schemaschemapublicz$Drop this schema instead of "public")superadd_argumentsadd_argumentr   )selfparser	__class__ w/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/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 rLtd| |d}|tvrftd|d	 }|d
 }|d rt	d
||}nd}|dkrtd d S t|  0}	|	d
| |	d
| W d    n1 s0    Y  d S )Ndatabaser   z2--router is deprecated. You should use --database.   )
stacklevelzUnknown database %sZ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   Z	DATABASESgetr   r   inputformatprintr   cursorexecute)
r   argsoptionsr   ZdbinfoZengineZdatabase_namer   Zconfirmr(   r   r   r   handle,   s.    
zCommand.handle)__name__
__module____qualname____doc__r   r   r,   __classcell__r   r   r   r   r	      s   r	   )r0   r"   Zdjango.core.managementr   r   Z	django.dbr   r   Zdjango.confr   Zdjango_extensions.settingsr   Z#django_extensions.utils.deprecationr   r	   r   r   r   r   <module>   s   