juf / doctrine-import-bundle
Generate Doctrine ORM entities and repositories from an existing database.
Package info
github.com/julfabre/doctrine-import-bundle
Type:symfony-bundle
pkg:composer/juf/doctrine-import-bundle
Requires
- php: ^8.2
- doctrine/dbal: ^4.6
- doctrine/doctrine-bundle: ^2.11 || ^3.0
- doctrine/inflector: ^2.0
- doctrine/orm: ^3.0
- doctrine/persistence: ^3.1 || ^4.0
- nette/php-generator: ^4.2
- symfony/config: ^6.4 || ^7.0 || ^8.0
- symfony/console: ^6.4 || ^7.0 || ^8.0
- symfony/dependency-injection: ^6.4 || ^7.0 || ^8.0
- symfony/http-kernel: ^6.4 || ^7.0 || ^8.0
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8
- phpunit/phpunit: ^11.5 || ^12.0 || ^13.0
- symfony/error-handler: ^6.4.44 || ^7.0 || ^8.0
- symfony/framework-bundle: ^6.4 || ^7.0 || ^8.0
Suggests
None
Provides
None
Conflicts
- symfony/doctrine-bridge: <6.4.2
Replaces
None
This package is auto-updated.
Last update: 2026-11-16 18:02:01 UTC
README
Generate Doctrine ORM entities and repositories from an existing database, for Symfony.
Doctrine ORM 3 removed orm:convert-mapping and orm:generate-entities. This bundle brings reverse
engineering back as a single command, with code you can keep: attributes, typed properties, explicit
column mapping, and a report of everything it could not map safely instead of guessed code.
composer require --dev juf/doctrine-import-bundle php bin/console generate:entities:from-database
Features
- One entity and one
ServiceEntityRepositoryper table, mapped with Doctrine attributes. - Singular class names, camelCase properties, explicit
name:andtype:on every column. - Identifiers (identity, assigned, composite), literal and
CURRENT_TIMESTAMPdefaults, indexes and unique constraints, comments. ManyToOneassociations for single-column foreign keys, with their inverseOneToManycollection.- Table filters, table prefixes (
wp_posts→Post), dry run, existing files kept unless--force. - Diagnostics for every table or column that cannot be mapped safely; exit code
1when the generation is incomplete. - Checked on PostgreSQL, MySQL, MariaDB and SQLite: the schema Doctrine computes from the generated entities matches the original database.
Example
CREATE TABLE author (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL); CREATE TABLE post ( id INT AUTO_INCREMENT PRIMARY KEY, author_id INT NOT NULL, title VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE );
#[ORM\Entity(repositoryClass: PostRepository::class)] #[ORM\Table(name: 'post')] class Post { #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(name: 'id', type: Types::INTEGER)] private ?int $id = null; #[ORM\Column(name: 'title', type: Types::STRING, length: 255)] private string $title; #[ORM\Column(name: 'created_at', type: Types::DATETIME_IMMUTABLE, options: ['default' => new CurrentTimestamp()])] private \DateTimeImmutable $createdAt; #[ORM\ManyToOne(targetEntity: Author::class, inversedBy: 'posts')] #[ORM\JoinColumn(name: 'author_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')] private ?Author $author = null; // getters and fluent setters... }
Author gets a posts collection with addPost() and removePost().
Requirements
PHP 8.2+, Symfony 6.4 / 7.x / 8.x, Doctrine ORM 3, Doctrine DBAL 4.6+, DoctrineBundle 2.11+ / 3.x.
Documentation
Installation, usage, configuration, diagnostics and known limitations.