- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
81 lines
1.6 KiB
PHP
81 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Database\Schema;
|
|
|
|
final class ForeignKeyDefinition
|
|
{
|
|
public readonly array $columns;
|
|
|
|
public ?string $referencedTable = null;
|
|
|
|
public array $referencedColumns = [];
|
|
|
|
public ForeignKeyAction $onUpdate = ForeignKeyAction::RESTRICT;
|
|
|
|
public ForeignKeyAction $onDelete = ForeignKeyAction::RESTRICT;
|
|
|
|
public ?string $name = null;
|
|
|
|
public function __construct(array $columns)
|
|
{
|
|
$this->columns = $columns;
|
|
}
|
|
|
|
public function references(string|array $columns): self
|
|
{
|
|
$this->referencedColumns = (array) $columns;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function on(string $table): self
|
|
{
|
|
$this->referencedTable = $table;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function onUpdate(ForeignKeyAction $action): self
|
|
{
|
|
$this->onUpdate = $action;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function onDelete(ForeignKeyAction $action): self
|
|
{
|
|
$this->onDelete = $action;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function cascadeOnUpdate(): self
|
|
{
|
|
return $this->onUpdate(ForeignKeyAction::CASCADE);
|
|
}
|
|
|
|
public function cascadeOnDelete(): self
|
|
{
|
|
return $this->onDelete(ForeignKeyAction::CASCADE);
|
|
}
|
|
|
|
public function nullOnDelete(): self
|
|
{
|
|
return $this->onDelete(ForeignKeyAction::SET_NULL);
|
|
}
|
|
|
|
public function restrictOnDelete(): self
|
|
{
|
|
return $this->onDelete(ForeignKeyAction::RESTRICT);
|
|
}
|
|
|
|
public function name(string $name): self
|
|
{
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
}
|