fahriztx/model-uuid
Laravel/PHP trait to add automatic UUIDs to Eloquent models. Generates a UUID when creating records and supports using UUIDs as primary keys or additional identifiers, reducing reliance on auto-increment IDs and easing integration across systems.
Pros:
Cons:
BINARY(16) indexing in MySQL/PostgreSQL) to avoid performance degradation on WHERE/JOIN clauses.Str::uuid() or custom providers (risk of inconsistency if not standardized).deleted_at still needs auto-increment).id from BIGINT to UUID or adding a secondary UUID column).spatie/laravel-permission) may assume integer keys; requires wrapper logic or forks.WHERE/JOIN operations post-migration.BINARY(16) storage and composite indexes where possible.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Schema Migration | High | Test rollback procedures; use zero-downtime migrations. |
| Foreign Key Constraints | High | Audit all ON DELETE CASCADE dependencies. |
| UUID Generation Collisions | Medium | Enforce UUIDv4 + database-level uniqueness. |
| Legacy Code Breaks | Medium | Implement a facade/alias for Model::find() to handle both UUID/int. |
| Indexing Overhead | Medium | Profile queries; optimize with partial indexes. |
ULID, UUIDv7).users, posts) ready for UUID primary keys? What’s the migration plan for foreign keys?Binary data would be truncated errors)?uuid-ossp functions in PostgreSQL, MySQL’s UUID() function quirks)?INSERT/SELECT operations.| Phase | Actionable Steps | Tools/Validation |
|---|---|---|
| Assessment | Audit all models/tables using integer keys. Identify foreign key dependencies. | php artisan db:show + manual review. |
| Pilot | Migrate a non-critical table (e.g., logs) to UUID. Monitor performance. |
Laravel Debugbar + New Relic. |
| Hybrid Phase | Add UUID as secondary key (e.g., id + uuid) to existing tables. |
Custom trait to support both keys. |
| Full Migration | Alter primary key to UUID; update all foreign keys. | Database migrations + CI/CD rollback. |
| Cleanup | Remove legacy integer keys (post-deprecation). | Feature flags for phased removal. |
id is integer (e.g., laravel-excel, spatie/laravel-medialibrary).
findOrFail($uuid) explicitly or patch packages.uuid-ossp for generation.CHAR(36) or BINARY(16) storage; avoid VARCHAR for indexing.CHAR(36) with custom collation.settings, configurations, or audit logs first.orders, payments).config or environment variables to toggle UUID usage per model.@deprecated to integer-based methods before removal.id collisions during PRs).UUID::fromString() calls; less intuitive than id = 123.user_id = "a1b2c3..." vs. user_id = 42).ON CONFLICT in PostgreSQL).BINARY(16) + composite indexes).Model::find(123) fails silently (enforce strict typing with findOrFail).DB::enableQueryLog() to identify UUID-related bottlenecks.Str::uuid() vs. database defaults).INSERT/UPDATE (benchmark with your load).EXPLAIN ANALYZE on UUID-heavy queries.| Failure
How can I help you explore Laravel packages today?