File tree Expand file tree Collapse file tree 5 files changed +38
-4
lines changed
Expand file tree Collapse file tree 5 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ backend/**/*.pyd
1919backend /.Python
2020backend /* .db
2121backend /* .sqlite3
22+ backend /data /prod_db.db
2223
2324# Dependencies
2425** /node_modules /
Original file line number Diff line number Diff line change 55 BACKEND_DIR : backend
66 PROD_HOST : vpsjim
77 PROD_DB_PATH : ~/pingmaster/data/sql_app.db
8+ CONTAINER_NAME : pingmaster_api_1
89
910tasks :
1011 install :
@@ -110,10 +111,27 @@ tasks:
110111 db:view :
111112 desc : Open the downloaded production database in VS Code
112113 cmds :
113- - code {{.BACKEND_DIR}}/data/prod_db.db
114+ - cursor {{.BACKEND_DIR}}/data/prod_db.db
114115
115116 db:manage :
116117 desc : Download and view the production database
117118 cmds :
118119 - task : db:download
119- - task : db:view
120+ - task : db:view
121+
122+ debug:prod:db :
123+ desc : Debug production database issues
124+ cmds :
125+ - ssh {{.PROD_HOST}} "docker logs {{.CONTAINER_NAME}}"
126+ - ssh {{.PROD_HOST}} "ls -la ~/pingmaster/data"
127+ - ssh {{.PROD_HOST}} "docker exec {{.CONTAINER_NAME}} ls -la /app/data"
128+
129+ logs:prod :
130+ desc : View production logs
131+ cmds :
132+ - ssh {{.PROD_HOST}} "docker logs {{.CONTAINER_NAME}}"
133+
134+ exec:prod :
135+ desc : Execute command in production container
136+ cmds :
137+ - ssh {{.PROD_HOST}} "docker exec -it {{.CONTAINER_NAME}} bash"
Original file line number Diff line number Diff line change 11from sqlalchemy import create_engine
22from sqlalchemy .orm import sessionmaker , declarative_base
3+ import os
34
4- SQLITE_URL = "sqlite:///./sql_app.db"
5+ # Créer le répertoire data s'il n'existe pas
6+ DATA_DIR = "/app/data"
7+ os .makedirs (DATA_DIR , exist_ok = True )
8+
9+ SQLITE_URL = f"sqlite:///{ DATA_DIR } /sql_app.db"
510
611engine = create_engine (SQLITE_URL )
712SessionLocal = sessionmaker (autocommit = False , autoflush = False , bind = engine )
Original file line number Diff line number Diff line change 1+ import logging
2+ import os
13from fastapi import FastAPI
24from app .api .endpoints import hello , messages
3- from app .db .session import init_db
5+ from app .db .session import init_db , SQLITE_URL
6+
7+ logging .basicConfig (level = logging .INFO )
8+ logger = logging .getLogger (__name__ )
49
510app = FastAPI (
611 title = "MonitoringDashboard API" ,
1015
1116@app .on_event ("startup" )
1217def startup_event ():
18+ logger .info (f"Using database at: { SQLITE_URL } " )
19+ logger .info (f"Current directory: { os .getcwd ()} " )
20+ logger .info (f"Directory contents of /app/data: { os .listdir ('/app/data' )} " )
1321 init_db ()
22+ logger .info ("Database initialized" )
1423
1524app .include_router (hello .router , prefix = "/api" )
1625app .include_router (messages .router , prefix = "/api" )
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ services:
1313 - " 8000:8000"
1414 volumes :
1515 - ./data:/app/data
16+ user : " ${UID}:${GID}"
1617 networks :
1718 - api_network
1819 # healthcheck:
You can’t perform that action at this time.
0 commit comments