fix(console): fix PostgreSQL connection + add Metabase Actions guide

- Fix console/main.py: import DB_URL instead of missing DB_PATH
- Add sqlalchemy text() import for connection test
- Replace file-exists check with actual PostgreSQL connection test
- Mask password in startup banner
- Add docs/METABASE_ACTIONS.md: complete guide for data entry via
  Metabase Actions (models, forms, dashboard layout, workflows)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-19 05:52:12 +00:00
parent 7b2a904498
commit 2c6b6e0160
2 changed files with 513 additions and 22 deletions

View File

@@ -8,10 +8,11 @@ Usage:
"""
import argparse
import os
import sys
from console.config import VERSION, APP_NAME, APP_SUBTITLE, DB_PATH
from sqlalchemy import text
from console.config import VERSION, APP_NAME, APP_SUBTITLE, DB_URL
def parse_args(argv=None):
@@ -27,20 +28,29 @@ def parse_args(argv=None):
)
parser.add_argument(
"--db",
default=DB_PATH,
help="Path to the vehicle database (default: auto-detected)",
default=DB_URL,
help="PostgreSQL connection URL (default: from config)",
)
return parser.parse_args(argv)
def _print_banner(db_path):
def _print_banner(db_url):
"""Print a startup banner before entering terminal mode."""
# Mask password in display
display_url = db_url
if '@' in db_url:
pre_at = db_url.split('@')[0]
post_at = db_url.split('@', 1)[1]
if ':' in pre_at.split('//')[-1]:
user = pre_at.split('//')[-1].split(':')[0]
display_url = f"postgresql://{user}:****@{post_at}"
border = "=" * 58
print(border)
print(f" {APP_NAME} v{VERSION}")
print(f" {APP_SUBTITLE}")
print(border)
print(f" DB : {db_path}")
print(f" DB : {display_url}")
print(border)
print()
@@ -49,20 +59,7 @@ def main(argv=None):
"""Main entry point: parse args, set up renderer, DB, and launch the app."""
args = parse_args(argv)
db_path = args.db
# Verify the database file exists before proceeding
if not os.path.isfile(db_path):
print(
f"Error: Database not found at '{db_path}'.\n"
f"\n"
f"Make sure the vehicle database exists. You can specify a\n"
f"custom path with the --db flag:\n"
f"\n"
f" python -m console --db /path/to/vehicle_database.db\n",
file=sys.stderr,
)
sys.exit(1)
db_url = args.db
# Lazy imports so the module can be loaded without curses available
# (e.g. during tests or when just checking --version).
@@ -71,9 +68,30 @@ def main(argv=None):
from console.core.app import App
# Print startup banner
_print_banner(db_path)
_print_banner(db_url)
# Test database connection before entering curses mode
db = Database(db_url)
try:
db._get_engine()
session = db._session()
session.execute(text("SELECT 1"))
session.close()
except Exception as e:
print(
f"Error: Cannot connect to database.\n"
f"\n"
f" URL: {db_url}\n"
f" Error: {e}\n"
f"\n"
f"Make sure PostgreSQL is running and the connection URL is correct.\n"
f"You can specify a custom URL with the --db flag:\n"
f"\n"
f" python -m console --db postgresql://user:pass@host/dbname\n",
file=sys.stderr,
)
sys.exit(1)
db = Database(db_path)
renderer = CursesRenderer()
app = App(renderer=renderer, db=db)