o
    ‹åg–  ã                   @   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   ú`/var/www/html/flaskapp/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 )z‰Run 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&    

	
