Table
Table
Represents a database table for migration actions.
class Table extends \Hazaar\DBI\Manager\Migration\Action\BaseActionExtends: Hazaar\DBI\Manager\Migration\Action\BaseAction
Encapsulates 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 $nameType: string
columns
public array $columnsType: array
add
public array $addType: array
alter
public array $alterType: array
Methods
create
Creates the table in the database.
public create(Adapter $dbi, ?string $user): boolReturns: bool
Validates required properties and logs errors if missing. Converts columns to arrays for creation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$dbi | Hazaar\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): voidReturns: void
Table-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 | Hazaar\DBI\Adapter | |
$user | string |
alter
public alter(Adapter $dbi): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$dbi | Hazaar\DBI\Adapter |
drop
public drop(Adapter $dbi): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$dbi | Hazaar\DBI\Adapter |
apply
Applies the given action to the table.
public apply(BaseAction $action): boolReturns: bool
This method processes the action by adding, altering, or dropping columns based on the properties of the provided BaseAction object.
Parameters
| Parameter | Type | Description |
|---|---|---|
$action | Hazaar\DBI\Manager\Migration\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): ?selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | Hazaar\DBI\Manager\Migration\Action\BaseAction |
reverse
public reverse(self $sourceTable): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$sourceTable | self |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000