
    jg+                     r    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
e      Zy)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                   ,     e Zd ZdZdZ fdZd Z xZS )Commandz&`reset_schema` command implementation.z-Recreates the public schema for this project.c                     t         |   |       |j                  dddddd       |j                  dd	d
dt        d       |j                  dt        dt        z         |j                  ddd
ddd       y )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__s     m/var/www/html/Stanley/venv/lib/python3.12/site-packages/django_extensions/management/commands/reset_schema.pyr   zCommand.add_arguments   s    f%mM 	 	

 	*W8EUU 	 	
 	"2Z]mm 	 	
 	*W8X7 	 	
    c                 b   |d   }|d   t         k7  r!t        j                  dt        d       |d   }t        j
                  j                  |      }|t        d|z        |j                  d      }|t        vrt        d      |d	   }|d
   }|d   rt        dj                  ||            }nd}|dk7  rt        d       y t        |   j                         5 }	|	j                  dj                  |             |	j                  dj                  |             d d d        y # 1 sw Y   y xY w)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-   s
             r   handlezCommand.handle,   s)   :&8 00MMNPkxyzx(H##''1>4x?@@H%++YZZv"=! / 06vfm/LNG Ge$%"))+vNN3::6BCNN-44V<= ,++s   AD%%D.)__name__
__module____qualname____doc__r   r   r5   __classcell__)r   s   @r   r   r      s    0:D
(#>r   r   )r9   r&   django.core.managementr   r   	django.dbr   r   django.confr   django_extensions.settingsr   #django_extensions.utils.deprecationr	   r    r   r   <module>rA      s-     < & !   9 K<>k <>r   