
    XhC                     (   d dl mZmZ d dlmZ d dlmZ d dlmZ d dl	Z	d dl
Z
d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZ d dlmZmZmZmZmZ  e
j        e
j                    e
j        e          Z d Z!edefd            Z" eddde"          Z#e#$                    eg ddg ddg           e#%                    e&          d             Z'e#(                    d          d             Z)e#(                    d          d             Z*e#+                    ej,                   e#+                    ej,                   e#+                    ej,                   e#+                    ej,                   e#+                    ej,                   dS )    )FastAPIHTTPException)CORSMiddlewareJSONResponse)asynccontextmanagerN)Config)command)MigrationContext)ScriptDirectory)engineBase)authprojects
candidatescommunicationsreports)levelc                     	 t           j                            t           j                            t           j                            t                                        } t           j                            | d          }t           j                            |          st          d|           t          |          }t          j	        d          }|st          d          |
                    d|           t          j                    5 }t          j        |          }|                                }t!          j        |          }|                                }t&                              d|pd            t&                              d|            ||k    r(t&                              d	           	 d
d
d
           d
S 	 d
d
d
           n# 1 swxY w Y   t&                              d           t+          j        |d           t&                              d           d
S # t.          $ rA}	t&                              d|	            t          dt3          |	                     d
}	~	ww xY w)z0Run database migrations using Alembic Python APIzalembic.iniz#Alembic configuration not found at DATABASE_URLz<DATABASE_URL environment variable is required for migrationszsqlalchemy.urlzCurrent migration: NonezLatest migration: zDatabase is up to dateNz)Upgrading database to latest migration...headz*Database migrations completed successfullyzError running migrations: zDatabase migration failed: )ospathdirnameabspath__file__joinexistsRuntimeErrorr	   getenvset_main_optionr   connectr   	configureget_current_revisionr   from_configget_current_headloggerinfor
   upgrade	Exceptionerrorstr)
current_diralembic_cfg_pathalembic_cfgdatabase_url
connectioncontextcurrent_rev
script_dirhead_reves
             "/home/runner/workspace/app/main.pyrun_migrationsr9      s   )Cgoobgoobgooh6O6O&P&PQQ7<<]CCw~~.// 	YWEUWWXXX -.. y00 	_]^^^##$4lCCC ^ 	&0<<G!6688K )4[AAJ!2244HKKEk.CVEEFFFKK7X77888h&&4555	 	 	 	 	 	 	 	 '	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  	?@@@V,,,@AAAAA C C C5!55666AQAABBBCsD   DH, B.G<H, 
H, GH, GAH, ,
I76<I22I7appc                   K   t          j        dd                                          dk    }|r)t                              d           t                       nt                              d           d W V  d S )NRUN_MIGRATIONS_ON_STARTUPtruezRunning database migrations...z7Migration on startup disabled. Run migrations manually.)r   r!   lowerr(   r)   r9   )r:   run_migrations_on_startups     r8   lifespanr@   A   sz       !#	*Ev N N T T V VZ` `  O4555MNNN	EEEEEE    #University Admission Management APIz>AI-powered university admission management system with FastAPI1.0.0)titledescriptionversionr@   )zhttp://localhost:3000zhttps://*.replit.appzhttps://*.replit.devT)GETPOSTPUTDELETE*)allow_originsallow_credentialsallow_methodsallow_headersc                 ,   K   t          dddi          S )Ni  detailzInternal server error)status_codecontentr   )requestexcs     r8   general_exception_handlerrV   _   s)      23   rA   /c                     K   ddddS )NrB   rC   running)messagerF   status r\   rA   r8   rootr]   g   s        9  rA   z/healthc                     K   ddiS )Nr[   healthyr\   r\   rA   r8   health_checkr`   o   s      i  rA   )-fastapir   r   fastapi.middleware.corsr   fastapi.responsesr   
contextlibr   r   loggingalembic.configr	   alembicr
   alembic.runtime.migrationr   alembic.scriptr   app.core.databaser   r   app.routersr   r   r   r   r   basicConfigINFO	getLogger__name__r(   r9   r@   r:   add_middlewareexception_handlerr+   rV   getr]   r`   include_routerrouterr\   rA   r8   <module>ru      s   * * * * * * * * 2 2 2 2 2 2 * * * * * * * * * * * * 				  ! ! ! ! ! !       6 6 6 6 6 6 * * * * * * * * * * * * * * K K K K K K K K K K K K K K  ', ' ' ' '		8	$	$+C +C +C\ 	
 	
 	
 	
 	
 g
/P	     [[[222%     y!!  "!    ! ! !   4;      8? # # #   :$ % % %   >( ) ) )   7> " " " " "rA   