o
    f                     @   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 rMe  dS e  dS )    N)
fileConfig)current_app)contextzalembic.envc                	   C   s8   z	t jd j W S  ttfy   t jd jj Y S w )Nmigrate)r   
extensionsdb
get_engine	TypeErrorAttributeErrorengine r   r   %/home/ubuntu/webapp/migrations/env.pyr      s
   r   c                   C   sB   zt  jjddddW S  ty    tt  jdd Y S w )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   sR   t d} tj| t dd t  t  W d   dS 1 s"w   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 }| 5}tjd|t d| t	  t
  W d   n1 s<w   Y  W d   dS W d   dS 1 sTw   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   sB   t tjddr|d }|j rg |d d < td d S d S 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   r   configure_argsgetr   connectr   r   r   r    r!   )r-   	conf_argsconnectabler.   r   r   r   run_migrations_onlineK   s$   


"r4   )logginglogging.configr   flaskr   alembicr   r   config_file_name	getLoggerr(   r   r   set_main_optionr   r   r   r   r"   r4   is_offline_moder   r   r   r   <module>   s"    

	#

