Table
Table
Represents a database table for migration actions.
class Table extends \Hazaar\DBI\Manager\Migration\Action\BaseActionEncapsulates table attributes such as name and columns, and provides methods for creating, altering, dropping, applying, diffing, and reversing table schema changes in migration processes.
Properties
name
The name of the table.
public string $namecolumns
public array $columnsadd
public array $addalter
public array $alterMethods
create
Creates the table in the database.
public create(Adapter $dbi, ?string $user): boolValidates required properties and logs errors if missing. Converts columns to arrays for creation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$dbi | Adapter | the database adapter instance |
$user | string | the user to grant permissions to, if applicable |
grantColumnSequences
Grants USAGE and SELECT on the sequences backing this table's serial columns.
private grantColumnSequences(Adapter $dbi, string $user): voidTable-level privileges (INSERT, SELECT, etc.) don't cover the sequence a serial column's default draws from — Postgres treats sequence access as a separate grant. Without this, inserts from the granted user fail with a "permission denied for sequence" error even though the table grant succeeded.
No-ops for backends that don't support sequences (e.g. SQLite), and for any sequence that isn't found under Postgres's implicit <table>_<column>_seq naming convention used for serial columns.
Parameters
| Parameter | Type | Description |
|---|---|---|
$dbi | Adapter | |
$user | string |
alter
public alter(Adapter $dbi): boolParameters
| Parameter | Type | Description |
|---|---|---|
$dbi | Adapter |
drop
public drop(Adapter $dbi): boolParameters
| Parameter | Type | Description |
|---|---|---|
$dbi | Adapter |
apply
Applies the given action to the table.
public apply(BaseAction $action): boolThis method processes the action by adding, altering, or dropping columns based on the properties of the provided BaseAction object.
Parameters
| Parameter | Type | Description |
|---|---|---|
$action | BaseAction | The action to be applied. It may contain 'add', 'alter', and 'drop' properties. - 'add': An array of columns to be added. - 'alter': An array of columns to be altered. - 'drop': An array of column names to be dropped. |
diff
public diff(BaseAction $table): ?selfParameters
| Parameter | Type | Description |
|---|---|---|
$table | BaseAction |
reverse
public reverse(self $sourceTable): selfParameters
| Parameter | Type | Description |
|---|---|---|
$sourceTable | self |
Generated by Hazaar API Doc Generator on Wed, 22 Jul 2026 14:10:07 +0000