ó
¸9—^c           @   sf   d  Z  d d l m Z m Z d d l m Z d d l m Z d d l m	 Z	 d e f d „  ƒ  YZ
 d S(	   s°   
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.
iÿÿÿÿ(   t   BaseCommandt   CommandError(   t   connections(   t   settings(   t   inputt   Commandc           B   s&   e  Z d  Z d Z d „  Z d „  Z RS(   s&   `reset_schema` command implementation.s-   Recreates the public schema for this project.c         C   s   t  t |  ƒ j | ƒ | j d d d d d d t d d ƒ| j d	 d
 d d d d d d d d ƒ| j d d d d d d d d d d ƒd  S(   Ns	   --noinputt   actiont   store_falset   destt   interactivet   defaultt   helps:   Tells Django to NOT prompt the user for input of any kind.s   -Rs   --routert   storet   routersB   Use this router-database instead of the one defined in settings.pys   -Ss   --schemat   schemat   publics$   Drop this schema instead of "public"(   t   superR   t   add_argumentst   add_argumentt   True(   t   selft   parser(    (    sT   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/reset_schema.pyR      s    c   
      O   s  | d } t  j j | ƒ } | d  k r; t d | ƒ ‚ n  | j d ƒ j d ƒ d } | d k rr t d	 ƒ ‚ n  | d
 } | d } | d r« t d j | | ƒ ƒ } n d } | d k rÆ d GHd  St | j	 ƒ  3 }	 |	 j
 d j | ƒ ƒ |	 j
 d j | ƒ ƒ Wd  QXd  S(   NR   s   Unknown database router %st   ENGINEt   .iÿÿÿÿt
   postgresqlt   postgresql_psycopg2t   postgiss8   This command can be used only with PostgreSQL databases.t   NAMER   R	   sÈ   
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: t   yess   Reset cancelled.s   DROP SCHEMA {} CASCADEs   CREATE SCHEMA {}(   R   R   R   (   R   t	   DATABASESt   gett   NoneR   t   splitR   t   formatR   t   cursort   execute(
   R   t   argst   optionsR   t   dbinfot   enginet   database_nameR   t   confirmR"   (    (    sT   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/reset_schema.pyt   handle#   s&    



(   t   __name__t
   __module__t   __doc__R   R   R*   (    (    (    sT   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/reset_schema.pyR      s   	N(   R-   t   django.core.managementR    R   t	   django.dbR   t   django.confR   t	   six.movesR   R   (    (    (    sT   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/reset_schema.pyt   <module>   s
   