- What does heymoon/doctrine-psql-enum actually do?
- It provides a Doctrine DBAL custom type that maps a PHP 8.1+ backed enum to a native PostgreSQL enum column created with CREATE TYPE ... AS ENUM. Conversion happens at the DBAL layer, so schema, queries, and migrations stay consistent without manual casts or string handling. It is not an Eloquent package and does not add Laravel model casts.
- Does this package work with Eloquent in Laravel?
- Not really. It targets Doctrine DBAL and Doctrine ORM, not Eloquent. Eloquent handles enums through casts on string or integer columns, and Laravel's $table->enum() on PostgreSQL emits a varchar plus a CHECK constraint rather than a native enum type. Adopting this package in an Eloquent-first app means adding Doctrine DBAL as a shim for a small ergonomic win, so backed-enum casts or a lookup table are usually the better choice.
- How do I install and register the type in a Laravel app?
- Run composer require heymoon/doctrine-psql-enum, then register the type in your DBAL type registry; with laravel-doctrine/orm that means the custom types section of config/doctrine.php. No service provider, config publishing, or container coupling is involved. Then annotate or attribute the entity column with the registered type name.
- Which Laravel and Doctrine DBAL versions are supported?
- Compatibility is driven by the DBAL major version rather than by Laravel itself, since the package is a DBAL type. DBAL 3 to 4 changed type registration and the Type contract materially, so confirm the supported DBAL range against your lockfile before scoping the work. PHP 8.1 or newer is required because the type maps backed enums.
- Will Doctrine migrations create the CREATE TYPE statement for my enum?
- Not automatically. DBAL schema tooling and the schema comparator diff entities against the database and do not emit CREATE TYPE for native enum types. You need to hand-author the CREATE TYPE in an initial migration, make sure it runs before the table creation, and add idempotent guards so fresh environments and repeated runs do not fail.
- How do I convert an existing varchar column to a native PostgreSQL enum?
- Use ALTER TABLE ... ALTER COLUMN ... TYPE ... USING (...) to cast the existing values to the new enum type. This rewrites the table and takes an ACCESS EXCLUSIVE lock, so on any non-trivial table it is a maintenance-window migration rather than a deploy-time one. Validate the data first and rehearse on a production-sized copy.
- What are the production risks of native PostgreSQL enums?
- Adding a value uses ALTER TYPE ... ADD VALUE, which has transaction-blocking caveats and cannot be used in the same transaction that added it. Renaming or removing a value requires creating a replacement type, rewriting every dependent column, and dropping the old type. Under zero-downtime deploy constraints that is materially harder than a CHECK constraint, and this package does nothing to soften the migration path.
- Is it safe to adopt a package with only 25 stars and no dependents?
- Treat it as code you are effectively adopting rather than a vetted dependency. Zero dependents is the sharper signal: there is no downstream population absorbing breakage before it reaches you, and it is a single-maintainer project. Have a fork-and-own contingency, and verify actual release history and commit activity before citing recency as a health signal.
- What are the alternatives to this package?
- martin-georgiev/postgresql-for-doctrine covers Postgres enums plus ranges, IP types, and other DBAL gaps with broader adoption. For Eloquent-first applications, backed-enum casts with a CHECK constraint or a lookup table avoid Doctrine entirely. Benchmark any build-or-buy decision against those options rather than against hand-rolling a Type subclass.
- How should I test enum columns using this type?
- Test against a real PostgreSQL instance rather than SQLite, because the type depends on native enum DDL. Cover round-trip reads and writes, invalid enum values, and the migration ordering that creates the type before the table. Also exercise fresh-install and upgrade paths, since idempotent CREATE TYPE guards are a common failure point.