From de24d9f78a39a7b257757bcfdd349c021c3eea66 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Wed, 24 Dec 2025 10:46:42 +1100 Subject: [PATCH] Try different approach - => _ --- app.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/app.py b/app.py index 70b9cf4..9b9906a 100644 --- a/app.py +++ b/app.py @@ -222,23 +222,16 @@ def run_sql_query(container_name: str, query: str) -> dict: Infers the database name from the Dokku container name. """ try: - # Infer DB name: dokku.postgres.my-service -> my-service - # Dokku services follow the naming: dokku.. + # Infer DB name: dokku.postgres.my-service -> my-service_db or my_service + # Dokku typically replaces hyphens with underscores in database names. parts = container_name.split(".", 2) service_name = parts[2] if len(parts) >= 3 else None - # In some setups, the DB name might be the service name minus '-db' or '-database' - # We'll use the service name but also handle the case where it might be a prefix - db_name = service_name - if service_name: - # Try to strip common suffixes if they are present - db_name = re.sub(r'-(db|database|postgres|mysql|mariadb|sql)$', '', service_name) + # Most common Dokku pattern: replace - with _ + db_name = service_name.replace("-", "_") if service_name else None if "postgres" in container_name: # Postgres: use psql with CSV-like output - # Target the specific database using -d. - # If the user specifically said it's 'function' while service is 'function-db', - # our regex 're.sub' will turn 'function-db' into 'function'. db_arg = ["-d", db_name] if db_name else [] cmd = [DOCKER, "exec", container_name, "psql", "-U", "postgres"] + db_arg + ["-c", query, "-A", "-F", ","] elif "mysql" in container_name or "mariadb" in container_name: