o
    If                     @   s   d dl 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
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dd Ze rUe  dS e  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/venv/lib/python3.10/site-packages/flask_migrate/templates/aioflask/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_metadata1   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_offline7   s   


"r"   c                 C   sx   dd }t jd j}|dd u r||d< tjd| t d| t  t  W d    d S 1 s5w   Y  d S )Nc                 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_directivesP   s   
z6do_run_migrations.<locals>.process_revision_directivesr   r-   )
connectionr   r   )	r   r   configure_argsgetr   r   r   r    r!   )r.   r-   	conf_argsr   r   r   do_run_migrationsL   s   

"r2   c               	      sZ   t  } |  4 I dH }|tI dH  W d  I dH  dS 1 I dH s&w   Y  dS )zRun migrations in 'online' mode.

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

    N)r   connectrun_syncr2   )connectabler.   r   r   r   run_migrations_onlinee   s
   .r6   )asynciologginglogging.configr   flaskr   alembicr   r   config_file_name	getLoggerr(   r   r   set_main_optionr   r   r   r   r"   r2   r6   is_offline_modeget_event_looprun_until_completer   r   r   r   <module>   s&    

	
