ORM Commands

ORM Commands

ORM commands facilitate the management of the Object-Relational Mapping layer, allowing for the initialization and updating of schemas, migration generation, schema visualization, and direct synchronization with the database.

Command Reference Table

CommandDescription
cycle:ormInit or update cycle schema from database and annotated classes
cycle:orm:migrateGenerate ORM schema migrations.
cycle:orm:renderDisplay ORM schema in your console.
cycle:orm:syncSync Cycle ORM schema with database without intermediate migration (risk operation).

Initializing or Updating ORM Schema

cycle:orm

This command initializes or updates the Cycle ORM schema by analyzing the database structure and annotated classes.

Usage

php artisan cycle:orm

Generating ORM Schema Migrations

cycle:orm:migrate

Use this command to generate migrations based on the current ORM schema. It's a crucial step for evolving the database schema in a controlled manner.

Usage

php artisan cycle:orm:migrate

Options

  • --r|run - Automatically run generated migration.
  • --s|split - Split migration into multiple files (one per table).

Example

Recording shows migration file generation on existing Domain Entities and their relationships.


Displaying ORM Schema

cycle:orm:render

To visualize the current ORM schema directly in your console, use the cycle:orm:render command. This can help with understanding the structure and relationships defined in your ORM.

Usage

php artisan cycle:orm:render

Options

  • --nc|no-color - Display output without colors.
  • --p|php - Display output as PHP code.

Example

Recording shows the visualization of the ORM schema in the console for existing App/Entities/Post entity.


Synchronizing ORM Schema with Database

cycle:orm:sync

This command directly synchronizes the Cycle ORM schema with the database. It bypasses the migration system and applies changes directly, which can be risky.

Usage

php artisan cycle:orm:sync
⚠️

Be cautious when using the cycle:orm:sync command, as it directly alters the database schema and can potentially lead to data loss.