a
    ÆZEg+  ã                   @   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__© úk/var/www/sistema_ama/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 r�t	d 
||¡ƒ}nd}|dkr¨tdƒ d S t|  ¡ �0}	|	 d 
|¡¡ |	 d 
|¡¡ W d   ƒ n1 sê0    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   