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

  1. Install and enable the Database Browser module
  2. Navigate to the database browser admin pages
  3. Attempt to execute a custom SQL query
  4. Observe that no SQL console interface exists
  5. 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
Command icon 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

oshi02 created an issue. See original summary.

mohnish s. yadav made their first commit to this issue’s fork.

mohnish s. yadav’s picture

Status: Active » Needs review

oshi02’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.