deploy
This commit is contained in:
parent
ff92f07645
commit
bafffd661a
30
app.py
30
app.py
|
|
@ -51,26 +51,16 @@ try:
|
||||||
get_diagnosis_by_prediction_id,
|
get_diagnosis_by_prediction_id,
|
||||||
get_engine,
|
get_engine,
|
||||||
)
|
)
|
||||||
|
engine = get_engine()
|
||||||
try:
|
MYSQL_AVAILABLE = engine is not None
|
||||||
engine = get_engine()
|
if MYSQL_AVAILABLE:
|
||||||
# quick connect test
|
try:
|
||||||
with engine.connect() as conn:
|
init_mysql_tables()
|
||||||
# initialize tables if needed
|
print("✓ MySQL database initialized")
|
||||||
try:
|
except Exception as init_err:
|
||||||
init_mysql_tables()
|
print(f"⚠️ Warning: Database tables initialization failed: {init_err}")
|
||||||
except Exception as init_err:
|
else:
|
||||||
|
print("[APP] MySQL disabled: no valid database configuration found")
|
||||||
print(f"⚠️ Warning: Database tables initialization failed: {init_err}")
|
|
||||||
print("✓ MySQL Database connected successfully")
|
|
||||||
MYSQL_AVAILABLE = True
|
|
||||||
except Exception as e:
|
|
||||||
import traceback
|
|
||||||
print('❌ MySQL not available at startup:')
|
|
||||||
print(f" Error: {e}")
|
|
||||||
print(" Cek: 1) MySQL Server berjalan? 2) .env credentials benar? 3) Database 'deteksi_pmk' ada?")
|
|
||||||
traceback.print_exc()
|
|
||||||
MYSQL_AVAILABLE = False
|
|
||||||
except Exception as import_err:
|
except Exception as import_err:
|
||||||
print(f"❌ Failed to import MySQL utilities: {import_err}")
|
print(f"❌ Failed to import MySQL utilities: {import_err}")
|
||||||
MYSQL_AVAILABLE = False
|
MYSQL_AVAILABLE = False
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,15 @@ def _build_database_uri():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[MYSQL] Ignoring invalid DATABASE_URL: {e}")
|
print(f"[MYSQL] Ignoring invalid DATABASE_URL: {e}")
|
||||||
|
|
||||||
db_host = os.environ.get('DB_HOST') or os.environ.get('MYSQLHOST', 'localhost')
|
db_host = (os.environ.get('DB_HOST') or os.environ.get('MYSQLHOST') or '').strip()
|
||||||
db_port = _normalize_port(os.environ.get('DB_PORT') or os.environ.get('MYSQLPORT'))
|
db_user = (os.environ.get('DB_USER') or os.environ.get('MYSQLUSER') or '').strip()
|
||||||
db_user = os.environ.get('DB_USER') or os.environ.get('MYSQLUSER', 'root')
|
|
||||||
db_password = os.environ.get('DB_PASSWORD') or os.environ.get('MYSQLPASSWORD', '')
|
db_password = os.environ.get('DB_PASSWORD') or os.environ.get('MYSQLPASSWORD', '')
|
||||||
db_name = os.environ.get('DB_NAME') or os.environ.get('MYSQLDATABASE', 'deteksi_pmk')
|
db_name = (os.environ.get('DB_NAME') or os.environ.get('MYSQLDATABASE') or '').strip()
|
||||||
|
|
||||||
|
if not db_host or not db_user or not db_name:
|
||||||
|
return None
|
||||||
|
|
||||||
|
db_port = _normalize_port(os.environ.get('DB_PORT') or os.environ.get('MYSQLPORT'))
|
||||||
|
|
||||||
if db_password:
|
if db_password:
|
||||||
return f"mysql+pymysql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}"
|
return f"mysql+pymysql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}"
|
||||||
|
|
@ -55,10 +59,13 @@ def _build_database_uri():
|
||||||
DATABASE_URI = _build_database_uri()
|
DATABASE_URI = _build_database_uri()
|
||||||
|
|
||||||
# Create engine
|
# Create engine
|
||||||
try:
|
if DATABASE_URI:
|
||||||
engine = create_engine(DATABASE_URI, echo=False, pool_pre_ping=True)
|
try:
|
||||||
except Exception as e:
|
engine = create_engine(DATABASE_URI, echo=False, pool_pre_ping=True)
|
||||||
print(f"[MYSQL] Database engine unavailable: {e}")
|
except Exception as e:
|
||||||
|
print(f"[MYSQL] Database engine unavailable: {e}")
|
||||||
|
engine = None
|
||||||
|
else:
|
||||||
engine = None
|
engine = None
|
||||||
|
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue