
    /i                        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	 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 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m Z m!Z!m"Z"m#Z#  e jH                  e jJ                  d       dD ]-  Z& e jN                  e&      jQ                  e jJ                         / defdZ) e)       Z*y)    N)FastAPI)CORSMiddleware)delete)text)SQLAlchemyError)router)Base)engine)utcnow)PasswordResetToken)UserRefreshTokenVendor	ViolationProductScrapingResultz4%(asctime)s - %(name)s - %(levelname)s - %(message)s)levelformat)appzapp.serviceszapp.apireturnc                     t        d      } | j                  t        dgdddgdg       | j                  d      dd	       }| j	                  t
        d
dg       | j	                  t        dg       | j	                  t        ddg       | j	                  t        ddg       | j	                  t        ddg       | S )NzMARCO Scraping)titlez#https://marco-fe.testyourapp.onlinez,^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?$T*)allow_originsallow_origin_regexallow_credentialsallow_methodsallow_headersstartupc            	        K   	 t        j                         4 d {   } | j                  t        j                  j
                         d {    | j                  t        d             d {    | j                  t        t              j                  t        j                  t               k  t        j                  j                  d       z               d {    | j                  t        d             d {    | j                  t        d             d {    | j                  t        d             d {    | j                  t        d             d {    | j                  t        d             d {    | j                  t        d             d {    | j                  t        d             d {    | j                  t        d	             d {    | j                  t        d
             d {    | j                  t        d             d {    | j                  t        d             d {    | j                  t        d             d {    | j                  t        d             d {    | j                  t        d             d {    | j                  t        d             d {    d d d       d {    y 7 7 7 7 7 7 7 7 7 7 c7 D7 %7 7 7 7 7 7 f7 F7 8# 1 d {  7  sw Y   y xY w# t        $ r}t!        d      |d }~ww xY ww)NzQALTER TABLE users ADD COLUMN IF NOT EXISTS tokens_invalid_before TIMESTAMPTZ NULLzLALTER TABLE violations ADD COLUMN IF NOT EXISTS barcode_number VARCHAR(255);zJALTER TABLE violations ADD COLUMN IF NOT EXISTS reference_id VARCHAR(255);zUALTER TABLE violations ADD COLUMN IF NOT EXISTS confirmation_count INTEGER DEFAULT 1;z]ALTER TABLE violations ADD COLUMN IF NOT EXISTS source_type VARCHAR(50) DEFAULT 'registered';zUALTER TABLE violations ADD COLUMN IF NOT EXISTS last_confirmed_date TIMESTAMPTZ NULL;zVALTER TABLE violations ADD COLUMN IF NOT EXISTS notification_sent_at TIMESTAMPTZ NULL;zIALTER TABLE violations ADD COLUMN IF NOT EXISTS vendor_name VARCHAR(512);zIALTER TABLE violations ADD COLUMN IF NOT EXISTS marketplace VARCHAR(255);z<ALTER TABLE violations ALTER COLUMN vendor_id DROP NOT NULL;zBALTER TABLE scraping_results ALTER COLUMN vendor_id DROP NOT NULL;zIALTER TABLE violations ADD COLUMN IF NOT EXISTS price_difference NUMERIC;zNALTER TABLE violations ADD COLUMN IF NOT EXISTS percentage_difference NUMERIC;zQALTER TABLE products ADD COLUMN IF NOT EXISTS last_scraped_date TIMESTAMPTZ NULL;zOALTER TABLE products ADD COLUMN IF NOT EXISTS last_execution_time VARCHAR(255);zOALTER TABLE scraping_results ADD COLUMN IF NOT EXISTS domain_name VARCHAR(255);zDatabase connection failed during startup. Check DATABASE_URL in .env (username/password/host/port/db) and ensure Postgres is running.)r
   beginrun_syncr	   metadata
create_allexecuter   r   r   where
expires_atr   used_atis_notr   RuntimeError)connes     ./var/www/html/marco-python-backend/app/main.py_create_tablesz"create_app.<locals>._create_tables6   s    W	||~ Q QmmDMM$<$<===llZ   ll-.44+66&(B-55<<TBD   llfh   lldf  
 lloq   llwy   lloq   llpr   llce   llce  
 llV  
 ll\   llce   llhj  
 llkm  
 llik  
 llik  ]Q Q Q=





]Q Q Q Qd  	n 	s  ML; K1L; -L&K4!L&/K70A-L&K:!L&?K= !L&!L "!L&L!L&%L&!L&L	!L&)L*!L&L!L&-L.!L&L!L&1L2!L&L!L&5L6!L&L!L&9L :!L&L"L& L; +L$,L; 0M1L; 4L&7L&:L&=L& L&L&L&	L&L&L&L&L&L&L&L&L& L&"L&$L; &L8,L/-L84L; 7M8L; ;	MMMMz/authauth)prefixtagsvendors)r1   z/api/productsproductsz/api/violations
violationsz/api	dashboard)r   N)
r   add_middlewarer   on_eventinclude_routerauth_routervendor_routerproduct_routerviolations_routerdashboard_router)r   r.   s     r-   
create_appr>       s    
(
)C - G%%  	 	\\)X Xt {7&B}I;7~oZLQ(1B,X'k]KJ    )+loggingfastapir   fastapi.middleware.corsr   
sqlalchemyr   r   sqlalchemy.excr   app.api.routes.productsr   r;   app.api.routes.authr9   app.api.routes.vendorsr:   app.api.routes.violationsr<   app.api.routes.dashboardr=   app.db.baser	   app.db.sessionr
   app.core.securityr   app.models.password_reset_tokenr   
app.modelsr   r   r   r   r   r   basicConfigINFOlogger_name	getLoggersetLevelr>   r    r?   r-   <module>rU      s      2   * < 5 : A ?  ! $ > U U   
,,A
 6 :KGk"++GLL9:
vG vr lr?   