Schema
Schema
Represents a database schema, including tables, views, constraints, indexes, functions, triggers, and extensions.
class Schema extends \Hazaar\DBI\Manager\StructProvides methods for importing, applying migrations, and converting to migration objects.
Properties
extensions
public array $extensionstables
public array $tablesviews
public array $viewsconstraints
public array $constraintsindexes
public array $indexesfunctions
public array $functionstriggers
public array $triggersignoreTables
private array $ignoreTables = array (
0 => 'schema_version',
1 => '__hz_file',
2 => '__hz_file_chunk',
)Methods
load
Load a schema from an array of versions.
public load(array $versions): selfParameters
| Parameter | Type | Description |
|---|---|---|
$versions | array |
import
Imports the current database schema using the provided adapter.
public import(Adapter $dbi): selfGathers extensions, tables, constraints, indexes, functions, triggers, and views from the database.
Parameters
| Parameter | Type | Description |
|---|---|---|
$dbi | Adapter | the database adapter instance |
applyVersion
Applies a migration version to the schema, updating its state.
public applyVersion(Version $version): voidProcesses all actions in the version's 'up' event and applies them to the schema.
Parameters
| Parameter | Type | Description |
|---|---|---|
$version | Version | the migration version to apply |
toMigration
Converts the schema to a Migration object representing the current state.
public toMigration(): MigrationGenerates a migration with all extensions, tables, views, constraints, indexes, functions, and triggers.
findActionOrComponent
public findActionOrComponent(string $name, array $haystack): nullParameters
| Parameter | Type | Description |
|---|---|---|
$name | string | |
$haystack | array |
create
Creates a new element in the schema.
private create(Action $action): voidParameters
| Parameter | Type | Description |
|---|---|---|
$action | Action | the action containing the specifications for the element to be created |
alter
Alters an existing element in the schema based on the provided action.
private alter(Action $action): voidUpdates the element with the new specification from the action.
Parameters
| Parameter | Type | Description |
|---|---|---|
$action | Action | the action containing the type and specifications for the element to alter |
drop
Drops an element based on the provided action.
private drop(Action $action): voidParameters
| Parameter | Type | Description |
|---|---|---|
$action | Action | the action containing the type and specifications for the element to drop |
dropTableReferences
Drops all constraints or indexes that reference the specified table.
private dropTableReferences(array $elements, string $table): voidParameters
| Parameter | Type | Description |
|---|---|---|
$elements | array | the array of constraints or indexes to search for references |
$table | string |
getElementName
Get the name of the element based on the action type.
private getElementName(ActionType $type): stringParameters
| Parameter | Type | Description |
|---|---|---|
$type | ActionType | the type of action to get the element name for |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:24 +0000