cycle/schema-builder
Cycle ORM Schema Builder lets you define and configure your ORM and database schema programmatically using annotations or custom generators. Register entities, map fields and columns, link tables, then compile the schema for Cycle ORM.
NOT NULL FK even though one of the sharing relations declared it nullable. The generator now takes the most permissive nullability across all relations sharing the constraint — the correct semantic for shared-column FK patterns (e.g., polymorphic-ish ownership, optional audit links, created_by/updated_by pairs). This is a behavioral correction, not an API change: no signatures changed, no config flags added. It tightens the reliability of the declarative model for relation-heavy domains.Registry, Compiler) may require training. Compare to existing migration tools (e.g., Laravel Migrations).NOT NULL to nullable, or vice versa in edge cases). This is the one non-trivial upgrade consideration: run PrintChanges / schema diffing before applying rather than assuming a patch release is DDL-inert. Risk is low and bounded — only schemas with relations sharing a generated FK are affected — but it should be an explicit gate in the upgrade checklist.ORM Strategy:
Schema Complexity:
Team Skills:
CI/CD Integration:
PrintChanges generator) for safe deployments? This is now mandatory for patch upgrades to 2.12.2.Performance:
Maintenance:
Assessment Phase:
Pilot Migration:
// Before (Laravel)
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
});
// After (Cycle ORM + Schema Builder)
$entity = new Definition\Entity()
->setRole('user')
->setClass(User::class)
->getFields()
->set('id', (new Definition\Field())->setType('primary'))
->set('name', (new Definition\Field())->setType('string(32)'));
$registry->register($entity);
$registry->linkTable($entity, 'default', 'users');
PrintChanges generator to validate schema diffs.Incremental Rollout:
Full Adoption:
$registry->addGenerator(new CustomTriggerGenerator());
Setup:
composer require cycle/schema-builder cycle/orm cycle/database
config/database.php) and Schema Builder (bootstrap/schema.php).Define Entities:
#[ORM\Entity]
class User {
#[ORM\Column(type: 'primary')]
public int $id;
#[ORM\Column(type: 'string(32)')]
public string $name;
}
Register Schema:
$registry = new Registry($dbal);
$registry->register(new UserEntityDefinition());
$schema = (new Compiler())->compile($registry);
$orm = $orm->withSchema(new ORM\Schema($schema));
Validate:
PrintChanges to preview changes:
$generator = new PrintChanges($registry, $schema);
$generator->generate();
Upgrade Gate (2.12.2):
composer update cycle/schema-builder to ^2.12.2.PrintChanges against a shadow/preview database and review every changed constraint — expect nullable FK adjustments only where relations share a generated FK.NOT NULL FK previously surfaced as a runtime insert failure, not a compile error, so existing tests may not cover it).Automate:
php artisan migrate or CI triggers).string(32) vs. text).PrintChanges for early detection.composer.lock, and never auto-merge schema-builder bumps without a diff review.PrintChanges review (see 2.12.2 above).Registry, Compiler, Definition\*), DDL semantics per target database, and the PrintChanges workflow.How can I help you explore Laravel packages today?