3
namespace Upside\Db\Schema;
7
protected string $ref_table;
10
protected array $ref_columns;
11
protected array $actions = [];
14
protected array $columns;
17
* @param string[] $columns
19
public function __construct(array $columns)
21
$this->columns = $columns;
24
protected function add_action(string $on, string $action): static
26
$action = \strtoupper($action);
28
if (!\in_array($action, ['RESTRICT', 'CASCADE', 'NO ACTION', 'SET NULL'])) {
32
$this->actions[$on] = $action;
37
public function get_referenced_table(): string
39
return $this->ref_table;
45
public function get_referenced_columns(): array
47
return $this->ref_columns;
53
public function get_columns(): array
55
return $this->columns;
58
public function get_actions(): array
60
return $this->actions;
63
public function references(string $table, string ...$columns): static
65
$this->ref_table = $table;
66
$this->ref_columns = $columns;
71
public function on_delete(string $action): static
73
return $this->add_action('ON DELETE', $action);
76
public function on_update(string $action): static
78
return $this->add_action('ON UPDATE', $action);