o
    ‹åg  ã                   @   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   ú]/var/www/html/flaskapp/venv/lib/python3.10/site-packages/flask_migrate/templates/flask/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 )z‰Run 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"    

	#

