Try different approach - => _
This commit is contained in:
15
app.py
15
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.<type>.<service-name>
|
||||
# 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:
|
||||
|
||||
Reference in New Issue
Block a user