Skip to content

fix(mysql): say which grant is missing when a routine's body is hidden - #290

Merged
jasdeepkhalsa merged 2 commits into
masterfrom
fix/mysql-routine-privilege
Nov 8, 2026
Merged

jasdeepkhalsa merged 2 commits into
masterfrom
fix/mysql-routine-privilege

Conversation

@jasdeepkhalsa

Copy link
Copy Markdown
Member

Fixes #286

What was wrong

On MySQL, a user with every privilege on a schema can see its routines listed in information_schema.ROUTINES. It still can't see their bodies unless it defined them or holds SHOW_ROUTINE (MySQL 8.0.20+) or global SELECT. For anyone else, SHOW CREATE PROCEDURE / SHOW CREATE FUNCTION returns the row with a NULL definition rather than an error. MySQLAdapter::getRoutines() passed that NULL to normalizeCreateStatement(), so the diff died with a TypeError.

Reproduced on MySQL 8.4 with a user granted ALL PRIVILEGES ON app.*:

  • Procedures and functions come back NULL.
  • SHOW CREATE TRIGGER and SHOW CREATE EVENT return their definitions, so only routines are affected.

MariaDB (11.4) returns the definition to the same user, so it is unaffected. PostgreSQL and SQLite don't use this path.

The fix

getRoutines() now stops with a DBException. The message names the routine and the grant that fixes it (GRANT SHOW_ROUTINE ON *.* TO <user>), or suggests connecting as the routine's definer.

Skipping the unreadable routine instead would be unsafe. On the source side the routine would read as missing, and the migration would drop it from the target.

Tests

tests/Unit/MySQLRoutinePrivilegeTest.php feeds getRoutines() the rows MySQL 8.4 returns to such a user.

  • With the fix, the diff stops with the new message.
  • Without the fix, the test errors with the reported TypeError.
  • A readable routine still comes back normalised.

Unit suite: 1103 tests, OK.

🤖 Generated with Claude Code

MySQL lists a routine to any user with privileges on its schema but shows
its body only to its definer or a user with SHOW_ROUTINE; everyone else
gets NULL from SHOW CREATE PROCEDURE/FUNCTION. getRoutines passed that
NULL on and the diff died with a TypeError. It now stops with a message
naming the routine and the grant. Skipping the routine instead would make
it read as dropped and put a DROP in the migration.

Fixes #286

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added bug mysql Related to Mysql php Pull requests that update php code postgres Related to Postgres sqlite Related to Sqlite labels Nov 6, 2026
Sonar caps a class at 20 methods; the helper made MySQLAdapter 21.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Nov 7, 2026

Copy link
Copy Markdown

@jasdeepkhalsa
jasdeepkhalsa merged commit b26c04d into master Nov 8, 2026
78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug mysql Related to Mysql php Pull requests that update php code postgres Related to Postgres sqlite Related to Sqlite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError in MySQLAdapter::normalizeCreateStatement() when comparing database schemas

1 participant