o
    uvXj	  ã                   @   sL   d Z ddlmZ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.
é    )ÚBaseCommandÚCommandError)Úconnections)Úsettings)Úinputc                       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                    sT   t t| ƒ |¡ |jdddddd� |jddd	d
ddd� |jddd	dddd� d S )Nz	--noinputÚstore_falseÚinteractiveTz:Tells Django to NOT prompt the user for input of any kind.)ÚactionÚdestÚdefaultÚhelpz-Rz--routerÚstoreÚrouterr   zBUse this router-database instead of the one defined in settings.pyz-Sz--schemaÚschemaÚpublicz$Drop this schema instead of "public")Úsuperr   Úadd_argumentsÚadd_argument)ÚselfÚparser©Ú	__class__© úo/var/www/html/myproject/venv/lib/python3.10/site-packages/django_extensions/management/commands/reset_schema.pyr      s   ý
þ

þzCommand.add_argumentsc           
      O   sà   |d }t j |¡}|d u rtd| ƒ‚| d¡ d¡d }|dvr&tdƒ‚|d }|d	 }|d
 r;td ||¡ƒ}nd}|dkrGtdƒ d S t|  	¡ �}	|	 
d |¡¡ |	 
d |¡¡ W d   ƒ d S 1 siw   Y  d S )Nr   zUnknown database router %sÚENGINEÚ.éÿÿÿÿ)Ú
postgresqlÚpostgresql_psycopg2Úpostgisz8This 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   Ú	DATABASESÚgetr   Úsplitr   ÚformatÚprintr   ÚcursorÚexecute)
r   ÚargsÚoptionsr   ÚdbinfoÚengineÚdatabase_namer   Úconfirmr(   r   r   r   Úhandle#   s*   ú"þzCommand.handle)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r0   Ú__classcell__r   r   r   r   r      s
    r   N)r4   Údjango.core.managementr   r   Ú	django.dbr   Údjango.confr   Ú	six.movesr   r   r   r   r   r   Ú<module>   s   