a
    wi                     @   s   d dl Z d dlmZ d dlmZ d dlmZ ejZeej e 	dZ
dd Zdd	 Zed
e  ejd jZdd Zdd Zdd Ze re  ne  dS )    N)
fileConfig)current_app)contextzalembic.envc                	   C   s<   zt jd j W S  ttfy6   t jd jj Y S 0 d S )Nmigrate)r   
extensionsdb
get_engine	TypeErrorAttributeErrorengine r   r   migrations/env.pyr      s    r   c                   C   sF   zt  jjddddW S  ty@   tt  jdd Y S 0 d S )NF)hide_password%z%%)r   urlrender_as_stringreplacer
   strr   r   r   r   get_engine_url   s    r   sqlalchemy.urlr   c                   C   s   t tdrtjd  S tjS )N	metadatas)hasattr	target_dbr   metadatar   r   r   r   get_metadata0   s    

r   c                  C   sP   t d} tj| t dd t  t  W d   n1 sB0    Y  dS )aF  Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    r   T)r   target_metadataliteral_bindsN)configget_main_optionr   	configurer   begin_transactionrun_migrations)r   r   r   r   run_migrations_offline6   s    

r"   c               	   C   s   dd } t jd j}|ddu r*| |d< t }| X}tjf |t d| t	  t
  W d   n1 sx0    Y  W d   n1 s0    Y  dS )zRun migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    c                 S   s:   t tjddr6|d }|j r6g |d d < td d S )NautogenerateFr   zNo changes in schema detected.)getattrr   cmd_optsupgrade_opsis_emptyloggerinfo)r   revision
directivesscriptr   r   r   process_revision_directivesV   s
    
z:run_migrations_online.<locals>.process_revision_directivesr   r-   N)
connectionr   )r   r   configure_argsgetr   connectr   r   r   r    r!   )r-   Z	conf_argsconnectabler.   r   r   r   run_migrations_onlineK   s    

r3   )loggingZlogging.configr   flaskr   alembicr   r   config_file_name	getLoggerr(   r   r   set_main_optionr   r   r   r   r"   r3   is_offline_moder   r   r   r   <module>   s    

	#