a
    ;]ri
                     @   s   d dl mZ d dlmZ d dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
 d dlmZ d dlZejZejdurzeej ejd eee jjjj d dlmZmZmZ d d	lmZmZ d d
lmZ ejZdd Z ddddZ!e!  dS )    )
fileConfig)fnmatchN)Path)engine_from_config)pooltextexc)context)DATABASEapp
DB_SESSION)CONFIG
merge_yaml)Eventc                 C   s8   |dkr4t jdd dD ]}t||r dS qdS )Ntablezalembic:excludetables,FT)r	   configget_sectionsplitr   )_nametype___Z___exclude r   ?/var/www/staging/api/app_home/migrations/satbots/alembic/env.pyinclude_object   s
    
r   )returnc                  C   s  t dtjd  d td} td}| r2|s:tdg }tjd dkr^|td d	  tjd d
v rttj dddd"}t	t
|dd}W d   n1 s0    Y  ||d d	  g }|D ]R}tjd dkrdnd|d  d|d  }|d|  d| | d|d   qt tjd   dt|  |D ]}t d|dd  tttji |dtjd}	|	 P}
tj|
td t  t  W d   n1 s0    Y  W d   n1 s0    Y  qFdS )zRun migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.
    zRunning in ZENVz mode	superusersuperuser_passwordzEPlease create superuser and superuser_password keys in your .env filetest	databasesZsatbots)Zdevelopmentr!   z/config.ymlrzutf-8)encoding)envN @host:portzpostgresql:///databasez databases to migrate: z

 -zsqlalchemy.)urlprefix	poolclass)
connectiontarget_metadata)printr   r   r   get
ValueErrorappendopenZ	root_pathr   yamlZ	safe_loadtitlelenr   r   r   config_ini_sectionr   NullPoolconnectr	   	configurer2   begin_transactionrun_migrations)r   r    Zyaml_databasesconfig_fileZtest_configr"   Zdb	host_portr,   connectabler1   r   r   r   r@      s>    

0*& 

r@   )"Zlogging.configr   r   syspathlibr   
sqlalchemyr   r   r   r   alembicr	   r8   r   config_file_namepathinsertstr__file__resolveparentsetupr
   r   r   r   r   Zmain.models.logs.eventr   metadatar2   r   r@   r   r   r   r   <module>   s$   

"2