Skip to content

Open the project's own database in magebox phpmyadmin open - #163

Merged
peterjaap merged 1 commit into
qoliber:mainfrom
Aquive:fix/phpmyadmin-open-project-db
Nov 12, 2026
Merged

peterjaap merged 1 commit into
qoliber:mainfrom
Aquive:fix/phpmyadmin-open-project-db

Conversation

@Aquive

@Aquive Aquive commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

There is one phpMyAdmin container for all projects, configured with a single server:

PMA_HOST: magebox-mysql-8.0

That host came from firstDBHost: the default MySQL version, or else whichever version Go's map iteration returned first. magebox phpmyadmin open always opened http://localhost:8036 on that server. A project on MariaDB 12.3, for example, landed on MySQL 8.0 and saw none of its own data. The only workaround was a second, hand-started phpMyAdmin container.

Alignment with the MageBox vision

This change brings the command in line with the principles in the project vision:

  • Set and forget. "The correct version is automatically selected based on the project configuration." Before, open ignored the project and the developer had to find the right server by hand. Now .magebox.yaml alone decides which server and database open.
  • Self-healing by default. A phpMyAdmin container that does not know the project's database server is repaired at the next natural moment, running open, without the developer needing to know a fix exists. Detection reads the running container's actual PMA_HOSTS rather than assuming the compose file matches it.
  • Integrations that provide clear added value. phpMyAdmin itself is unchanged. MageBox only adds what it uniquely knows, namely which container and database belong to this project. It does not rebuild any phpMyAdmin functionality.
  • No manual operations. The workaround this replaces, a second hand-started phpMyAdmin container per database version, is exactly the kind of manual setup MageBox exists to remove.

Fix

Compose (internal/docker/compose.go)

  • phpMyAdmin now gets every MySQL and MariaDB container in PMA_HOSTS, with readable labels in PMA_VERBOSES (MySQL 8.0, MariaDB 12.3). PMA_HOST is no longer set, because the image ignores PMA_HOSTS whenever it is present.
  • The order is fixed: the default MySQL first, else the default MariaDB, then each engine in version order. The server number in a URL is the position in that list, so it must not depend on map order. Server 1 stays the default database, as before.
  • firstDBHost is replaced by dbHosts and removed.

magebox phpmyadmin open (cmd/magebox/phpmyadmin.go)

  • In a project directory it resolves the project's DB container (same getDbInfo as magebox db), finds its position in the running container's PMA_HOSTS (via docker inspect), and opens index.php?route=/database/structure&server=N&db=<project db>.
  • Self-healing: if the running container does not list that host (created by an older release, or before this project started), the compose file is regenerated. The environment then differs, so compose up -d recreates the container, and the lookup runs again.
  • If the project's DB container is not running, it warns. Outside a project, or if the server still cannot be found, it opens the start page as before.

Docs and changelog: commands.md, services/phpmyadmin.md, and an [Unreleased] entry in CHANGELOG.md.

Testing

  • Unit tests:
    • PMA_HOSTS/PMA_VERBOSES rendering and the absence of PMA_HOST
    • deterministic dbHosts ordering, table-driven
    • server-index lookup from the container env, including a pre-upgrade container that only has PMA_HOST
    • URL building
  • Manual check against a real phpmyadmin:latest container with PMA_HOSTS=magebox-mysql-8.0,magebox-mariadb-12.3: server=2&db=<db> opens MariaDB 12.3 / <db>, and server=1 opens MySQL 8.0.
  • make lint: 0 issues
  • make test: passes

The shared phpMyAdmin container knew a single server (PMA_HOST): the
default MySQL version, or another version picked by map iteration
order. `open` always went to that server's start page, so a project
on another MySQL or MariaDB version showed the wrong server and none
of its data.

phpMyAdmin now gets every MySQL and MariaDB container in PMA_HOSTS,
in a fixed order with the default first, labelled by version. `open`
looks up the project's database container in the running container's
PMA_HOSTS and opens `?server=N&db=<name>` there. If the container does
not list it yet, the compose file is regenerated, which makes compose
recreate the container. Outside a project it opens the start page as
before.
@peterjaap
peterjaap merged commit 67b1975 into qoliber:main Nov 12, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants