comunedifirenze/doctrine2-exporter
Exporter that converts MySQL Workbench .mwb models into Doctrine 2 schemas. Install via Composer and run the CLI to generate YAML schema or annotation-based entities, with options for namespaces, repositories, relations, nullability, cascades, and more.
.mwb) models to Doctrine 2 entities, aligning with PHP/Laravel’s ORM-centric architecture. It abstracts database schema design into reusable, type-hinted entities, reducing manual mapping effort.doctrine/dbal and doctrine/orm), enabling integration with Eloquent’s underlying infrastructure if needed.MappingDriver.App\Models\ namespace, fillable/guarded attributes).mysql-workbench-schema-exporter/core as a transitive dep).artisan via custom commands or post-install hooks..mwb files can be version-controlled alongside Laravel codebase.doctrine/dbal (for migrations) or laravel-doctrine/orm (if using Doctrine ORM).| Risk Area | Severity | Mitigation |
|---|---|---|
| PHP Version Mismatch | High | Pin PHP 7.2+ in composer.json or use platform-check to enforce compatibility. |
| Doctrine vs. Eloquent | Medium | Abstract generated entities into a shared layer (e.g., App\Entities\) and map to Eloquent models. |
| Namespace Conflicts | Low | Configure bundleNamespace/entityNamespace to match Laravel’s App\Models\. |
| Annotation Overhead | Medium | Use YAML output + Doctrine’s YamlDriver to avoid annotation parsing in Laravel. |
| Lack of Laravel-Specific Features | High | Post-process output to add Laravel traits (e.g., HasFactory, SoftDeletes). |
Why Doctrine 2?
Output Format Preference
CI/CD Integration
.mwb files be versioned? (e.g., Git LFS for binary files)Long-Term Maintenance
doctrine/dbal schema tools)?laravel-doctrine/orm package to enable Doctrine ORM alongside Eloquent.composer.json to avoid PHP 5.4 legacy code..mwb → generate entities.Phase 1: Proof of Concept
composer require --dev mysql-workbench-schema-exporter/doctrine2-exporter
.mwb file to YAML/Annotations and validate against existing Laravel models.vendor/bin/mysql-workbench-schema-export CLI or wrap in a custom Artisan command.Phase 2: Integration Layer
laravel-doctrine/orm.config/doctrine.php to map namespaces (e.g., App\Entities).use \Illuminate\Database\Eloquent\Model;).Phase 3: CI/CD Automation
.mwb → generate entities on schema changes.# .github/workflows/schema-export.yml
name: Export Schema to Entities
on: [push]
jobs:
export:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: composer install
- run: vendor/bin/mysql-workbench-schema-export input.mwb --format=annotation --output=app/Entities/
| Component | Compatibility | Workaround |
|---|---|---|
| Laravel Eloquent | Low (outputs Doctrine entities) | Post-process annotations or use a hybrid ORM setup. |
| Laravel Migrations | Medium (Doctrine schema ≠ Laravel migrations) | Sync migrations manually or use doctrine/dbal to generate Laravel-style migrations. |
| PHPUnit Testing | High (Doctrine entities work with PHPUnit) | Ensure test doubles mock Doctrine’s EntityManager. |
| Laravel Scout | Low (requires Eloquent models) | Rebuild searchable models from Doctrine entities. |
composer require laravel-doctrine/orm mysql-workbench-schema-exporter/doctrine2-exporter
config/doctrine.php:
'orm' => [
'entity_managers' => [
'default' => [
'mapping_types' => [
'string' => 'string',
// ... other mappings
],
'naming_strategy' => 'doctrine.orm.naming_strategy.underscore',
],
],
],
app/Entities/.App\Entities\User → App\Models\User.bundleNamespace, entityNamespace, etc., for Laravel.README.md for onboarding.created_at vs. date_created).doctrine:schema:validate to check entity-schema consistency.#laravel-doctrine on Discord)..mwb complexity (test with large schemas).How can I help you explore Laravel packages today?