3
tg                 @   s   d dl mZ 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jdZdd Ze	jd	ee jjd
d ejd jZdd Zdd Zdd Zej re  ne  dS )    )with_statementN)
fileConfig)current_app)contextzalembic.envc               C   s4   yt jd jj S  tk
r.   t jd jjS X d S )Nmigrate)r   
extensionsdb
get_engine	TypeErrorengine r   r   migrations/env.pyr	      s    r	   zsqlalchemy.url%z%%r   c               C   s   t tdrtjd  S tjS )N	metadatas)hasattr	target_dbr   metadatar   r   r   r   get_metadata+   s    

r   c           	   C   s<   t jd} tj| t dd tj  tj  W dQ R X 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.

    zsqlalchemy.urlT)urltarget_metadataliteral_bindsN)configget_main_optionr   	configurer   begin_transactionrun_migrations)r   r   r   r   run_migrations_offline1   s
    

r   c              C   sd   dd } t  }|j D}tjf |t | dtjd j tj  tj	  W dQ R X W dQ R X 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j r6g |d d < tj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_directivesQ   s
    
z:run_migrations_online.<locals>.process_revision_directives)
connectionr   r'   r   N)
r	   connectr   r   r   r   r   configure_argsr   r   )r'   connectabler(   r   r   r   run_migrations_onlineF   s    

r,   )
__future__r   loggingZlogging.configr   flaskr   alembicr   r   config_file_name	getLoggerr"   r	   set_main_optionstrr   replacer   r   r   r   r   r,   is_offline_moder   r   r   r   <module>   s"   

 