https://github.com/salaheddine-ghannouch/data_explorer_module
A custom Drupal module that visualizes and analyzes the database structure. It maps relationships between entity tables, field tables, and revisions in an interactive graph view. The tool lets developers search where specific data is stored and preview joined results directly in the admin UI.
https://github.com/salaheddine-ghannouch/data_explorer_module
cms drupal twig
Last synced: 4 months ago
JSON representation
A custom Drupal module that visualizes and analyzes the database structure. It maps relationships between entity tables, field tables, and revisions in an interactive graph view. The tool lets developers search where specific data is stored and preview joined results directly in the admin UI.
- Host: GitHub
- URL: https://github.com/salaheddine-ghannouch/data_explorer_module
- Owner: SalahEddine-Ghannouch
- Created: 2025-11-10T18:34:50.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-11-10T18:39:18.000Z (5 months ago)
- Last Synced: 2025-11-10T20:29:58.113Z (5 months ago)
- Topics: cms, drupal, twig
- Language: PHP
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Drupal Data Explorer Module
A custom Drupal module that visualizes and analyzes the database structure. It maps relationships between entity tables, field tables, and revisions in an interactive graph view. The tool lets developers search where specific data is stored and preview joined results directly in the admin UI.
## Features
### π Schema Explorer
Auto-scans Drupal tables (node__, taxonomy__, users__, etc.) and shows entityβfield relationships.
### πΈοΈ Visual Relationship Graph
Interactive graph view showing relationships between base tables and their field tables (like node_field_data β node__body, etc.).
### π§Ύ Smart Query Builder
GUI that lets you pick an entity (e.g. Node β Article), choose fields, and auto-build SQL queries with JOINs.
### πΎ Data Exporter
Export joined results as CSV/JSON (useful for content migration or debugging).
### π§ Search by Field or Value
Search "where is this string stored?" β the tool scans tables to find possible locations (like finding the field where "Welcome to Inwi" is saved).
### βοΈ Drupal Integration Mode
Works as a Drupal admin module (accessible at `/admin/tools/data-explorer`).
## Installation
1. Copy the `data_explorer` module to your Drupal installation:
```
modules/custom/data_explorer/
```
2. Enable the module:
- Via Drush: `drush en data_explorer`
- Via Admin UI: Go to Extend (`/admin/modules`), find "Data Explorer" and enable it
3. Grant permissions:
- Go to People β Permissions (`/admin/people/permissions`)
- Grant "Access Data Explorer" permission to appropriate roles
## Usage
### Accessing the Tool
Navigate to `/admin/tools/data-explorer` in your Drupal site.
### Schema Explorer Tab
- Automatically displays all Drupal tables organized by entity type
- Shows table types (base, data, field_data, revision, etc.)
- Lists all columns for each table with their data types
### Relationship Graph Tab
- Visualizes relationships between:
- Base tables and data tables
- Entity tables and field tables
- Revision tables and revision data tables
- Filter by entity type to focus on specific entities
### Query Builder Tab
1. Select an entity type (e.g., Node, User, Taxonomy Term)
2. Optionally select a bundle (e.g., Article, Page)
3. Choose fields to include in the query
4. Click "Build & Execute Query" to see results
5. Export results as CSV or JSON
### Search Tab
**Search by Value:**
- Enter a search term (e.g., "Welcome to Inwi")
- The tool searches across all string columns in all tables
- Results show which tables contain the value and matching rows
**Search by Field Name:**
- Enter a field or table name
- Results show matching tables and columns
## API Endpoints
The module provides JSON API endpoints for programmatic access:
- `GET /admin/tools/data-explorer/api/schema` - Get full database schema
- `GET /admin/tools/data-explorer/api/relationships?entity_type=node&bundle=article` - Get relationships
- `GET /admin/tools/data-explorer/api/search?term=search_term&type=value` - Search database
- `POST /admin/tools/data-explorer/api/query` - Execute a query (body: `{"query": "SELECT ..."}`)
## Security
- Only users with "Access Data Explorer" permission can use the tool
- Query execution only allows SELECT queries
- Dangerous SQL keywords (DROP, DELETE, UPDATE, etc.) are blocked
- All queries are executed through Drupal's database abstraction layer
## Requirements
- Drupal 9, 10, or 11
- PHP 7.4 or higher
## Development
### File Structure
```
data_explorer/
βββ data_explorer.info.yml # Module definition
βββ data_explorer.module # Module hooks
βββ data_explorer.routing.yml # Routes
βββ data_explorer.services.yml # Service definitions
βββ data_explorer.libraries.yml # Asset libraries
βββ src/
β βββ Controller/
β β βββ DataExplorerController.php # Main page controller
β β βββ DataExplorerApiController.php # API endpoints
β βββ Service/
β βββ SchemaExplorerService.php # Schema scanning
β βββ RelationshipMapperService.php # Relationship mapping
β βββ QueryBuilderService.php # Query building
β βββ DataExporterService.php # Data export
β βββ SearchService.php # Search functionality
βββ css/
β βββ data-explorer.css # Styles
βββ js/
βββ data-explorer.js # Frontend JavaScript
```
### Extending the Module
To add a custom visualization library (e.g., D3.js or vis.js) for the relationship graph:
1. Add the library to `data_explorer.libraries.yml`
2. Update `js/data-explorer.js` in the `renderRelationshipGraph()` function
3. Enhance the graph visualization with interactive features
## Troubleshooting
**Module not appearing in Extend list:**
- Ensure the module is in `modules/custom/data_explorer/`
- Clear Drupal cache: `drush cr`
**Permission denied:**
- Grant "Access Data Explorer" permission to your user role
**No tables showing:**
- Ensure you have entities in your Drupal site
- Check database connection is working
**Query errors:**
- Only SELECT queries are allowed
- Check that table names are correct
- Ensure proper JOIN syntax
## License
This is a custom module. Modify as needed for your project.
## Support
For issues or questions, check the Drupal logs at `/admin/reports/dblog`.