Type
Type
Represents a custom database type (ENUM or composite) for migration actions.
class Type extends \Hazaar\DBI\Manager\Migration\Action\BaseActionExtends: Hazaar\DBI\Manager\Migration\Action\BaseAction
Encapsulates type attributes such as name, kind, enum values, and composite fields. Provides methods for creating, altering, dropping, and diffing types in migration processes.
Enum values and composite fields can only be safely altered in place when new entries are appended to the end of the existing list (ALTER TYPE ... ADD VALUE / ADD ATTRIBUTE). Anything else - a removed, reordered, renamed, or retyped entry - requires the type to be dropped and recreated, which Hazaar\DBI\Manager\Snapshot::compareTypes handles by emitting explicit DROP and CREATE actions (with a warning, since PostgreSQL will CASCADE the drop to anything using the type).
Properties
name
The name of the type.
public string $nameType: string
kind
The kind of type - ENUM or COMPOSITE.
public TypeKind $kindType: Hazaar\DBI\Manager\Migration\Enum\TypeKind
values
The enum values, for ENUM types only.
public array $valuesType: array
fields
The composite fields, for COMPOSITE types only.
public array $fieldsType: array
Methods
create
Creates the type in the database.
public create(Adapter $dbi, ?string $user): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$dbi | Hazaar\DBI\Adapter | the database adapter instance |
$user | string | not used for types, included for interface consistency |
alter
Alters the type in the database.
public alter(Adapter $dbi): boolReturns: bool
Only supports additive changes: new enum values or new composite fields appended to the end of the type. This action's values/fields hold only the entries being added.
Parameters
| Parameter | Type | Description |
|---|---|---|
$dbi | Hazaar\DBI\Adapter | the database adapter instance |
drop
Drops the type from the database.
public drop(Adapter $dbi): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$dbi | Hazaar\DBI\Adapter | the database adapter instance |
apply
Apply an ALTER action to this type, appending the new values/fields it carries.
public apply(BaseAction $action): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$action | Hazaar\DBI\Manager\Migration\Action\BaseAction |
diff
Finds an additive-only difference between this type and another.
public diff(BaseAction $action): ?selfReturns: self
Returns a diff containing only newly appended enum values or composite fields. Returns null both when the types are identical and when the difference is not a simple append (a removal, reorder, rename, or retype) - use Hazaar\DBI\Manager\Migration\Action\Type::isIdentical to tell those two cases apart.
Parameters
| Parameter | Type | Description |
|---|---|---|
$action | Hazaar\DBI\Manager\Migration\Action\BaseAction |
isIdentical
Determines whether this type is identical to another, including kind, values, and fields.
public isIdentical(self $action): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$action | self |
serializeDrop
Serializes the type for drop operations.
public serializeDrop(): mixedReturns: mixed
diffValues
Diffs enum values, returning only values appended after the current list.
private diffValues(self $action): ?selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$action | self |
diffFields
Diffs composite fields, returning only fields appended after the current list.
private diffFields(self $action): ?selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$action | self |
fieldsMatch
private fieldsMatch(array $a, array $b): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$a | array | |
$b | array |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000