feat(console): add bin/camelia-orm with seed and make commands
Tests / PHP 8.4 (push) Failing after 3m23s

A command line for the library, kept deliberately small: no console
component, no dependency added to the consumer's tree.

- Application/Command/Input/Output: parsing, dispatch, exit codes and
  capturable output. Commands return an exit code instead of calling exit(),
  so every one is testable.
- seed: runs the registered SeederRunner inside one transaction, with
  --list and --only=name[,name].
- doctor: one round-trip that fails loudly when the DSN is wrong.
- make:model and make:seeder: live scaffolding into the consumer's code,
  sharing name validation, the overwrite guard and directory creation
  through MakeCommand.

The binary ships an empty runner; an application composes SeedCommand into
its own Application to register its seeders.
This commit is contained in:
dgarcia committed 2026-11-15 13:31:14 -03:00
1 parent 2acf2cc099
commit a655a6f3ae
16 files changed
+1576

No files matched your search

+48
View File
@@ -110,6 +110,54 @@ $orm->transaction(function (Orm $orm) {
Nested calls use savepoints and the original exception is rethrown.
## Seeders
A seeder fills reference or bootstrap data and must be safe to run twice. The runner executes the
batch inside one transaction, so a failure writes nothing.
```php
final class PermissionsSeeder extends AbstractSeeder
{
public function name(): string
{
return 'permissions';
}
public function run(Orm $orm): void
{
$repository = $orm->repository(PermissionModel::class);
foreach (Permission::cases() as $permission) {
$this->seedOnce($repository, ['code' => $permission->value], [
'module' => $permission->module(),
'action' => $permission->action(),
]);
}
}
}
$report = (new SeederRunner($orm))->addMany([new PermissionsSeeder()])->run();
```
Full guide in [`docs/SEEDING.md`](docs/SEEDING.md).
## Command line
`bin/camelia-orm` ships the commands that need no knowledge of your code; the scaffolding commands
write into the current directory, so run it from your project root.
```bash
vendor/bin/camelia-orm # list commands
vendor/bin/camelia-orm doctor # check the connection from CAMELIA_DB_*
vendor/bin/camelia-orm make:model Invoice --table=invoices --dir=src/Models
vendor/bin/camelia-orm make:seeder RolesSeeder --dir=database/seeders
vendor/bin/camelia-orm seed --list
vendor/bin/camelia-orm seed --only=permissions,roles
```
`seed` runs whatever `SeederRunner` is wired to the command; the binary ships an empty runner, so an
application registers its own seeders by composing `SeedCommand` into its own `Application`.
## Errors
Every read and write throws on failure. Silent degradation to `[]` is deliberately absent: it hides