Problem/Motivation
Currently, the Database Browser module allows users to inspect database tables
through predefined listing, filtering, sorting, and pagination interfaces.
However, advanced users and administrators often need more flexibility for
querying Drupal database tables directly.
At present, users must rely on external tools such as phpMyAdmin, Adminer,
or direct MySQL terminal access to execute custom SQL queries for debugging,
reporting, analytics, and data inspection.
The module lacks a secure readonly SQL console that allows administrators
to execute custom raw SQL queries directly from the Drupal UI.
This feature would:
- Reduce dependency on external database tools
- Provide a Drupal-native database inspection experience
- Allow quick debugging and analytics inside Drupal admin UI
- Improve developer and site builder productivity
The console should support readonly queries only and prevent destructive
database operations.
Steps to reproduce
- Install and enable the Database Browser module
- Navigate to the database browser admin pages
- Attempt to execute a custom SQL query
- Observe that no SQL console interface exists
- User must switch to external tools like phpMyAdmin
Proposed resolution
Add a readonly SQL console page inside the Database Browser module.
Proposed functionality:
- Add admin page:
/admin/reports/database-browser/sql-console - Provide textarea/editor for entering SQL queries
- Allow execution of readonly queries only:
- SELECT
- SHOW
- DESCRIBE
- EXPLAIN
- Block destructive queries:
- INSERT
- UPDATE
- DELETE
- DROP
- ALTER
- TRUNCATE
- CREATE
- REPLACE
- Validate queries before execution
- Display query execution errors safely
- Render query results in Drupal table render arrays
- Add pagination support for large result sets
- Limit maximum returned rows for performance protection
- Log executed queries using Drupal logger channel
- Add dedicated permission:
access readonly sql console
Potential future enhancements:
- SQL syntax highlighting
- Autocomplete for tables and columns
- Query history
- CSV export
- Execution time analytics
Remaining tasks
- Create admin route and controller/form
- Create SQL query validation service
- Implement readonly keyword restrictions
- Add query execution handling using Drupal DBAL
- Render query results dynamically
- Add permissions and access checks
- Add pagination support
- Add query logging
- Write automated tests
- Add README documentation
User interface changes
New admin page:
/admin/reports/database-browser/sql-console
The page will include:
- SQL query textarea/editor
- Execute query button
- Readonly warning banner
- Result table display
- Error message area
- Execution metadata:
- Execution time
- Returned row count
API changes
New internal services may be added:
- Readonly SQL validator service
- SQL execution service
Possible future extensibility:
- Alter allowed query types
- Alter blocked keywords
- Alter query result rendering
Data model changes
No database schema changes are currently proposed.
Optional future enhancements:
- Add query history table
- Add saved query storage
- Add query analytics tracking
Issue fork database_browser-3589701
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
mohnish s. yadavComment #6
oshi02 commented