Snapshot
Snapshot
Represents a database schema snapshot, including version, comment, and migration details.
class Snapshot extends \Hazaar\Model\StructExtends: Hazaar\Model\Struct
Provides methods for creating, comparing, setting, saving, and retrieving schema snapshots and migrations.
Properties
version
The version information for the snapshot.
public Version $versionType: Hazaar\DBI\Manager\Version
comment
The comment associated with the snapshot.
public string $commentType: string
migration
The migration object associated with the snapshot.
public Migration $migrationType: Hazaar\DBI\Manager\Migration
Methods
create
Creates a new Snapshot instance with the provided comment and a version number based on the current date and time.
public create(string $comment): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$comment | string | the comment to associate with the snapshot |
compare
Compare a master schema to a compare schema and generate a migration.
public compare(Schema $masterSchama, Schema $compareSchema): ?MigrationReturns: Hazaar\DBI\Manager\Migration
This method will compare the master schema to the compare schema and generate a migration that can be used to update the master schema to match the compare schema.
Parameters
| Parameter | Type | Description |
|---|---|---|
$masterSchama | Hazaar\DBI\Manager\Schema | |
$compareSchema | Hazaar\DBI\Manager\Schema |
setSchema
Sets the schema for the snapshot.
public setSchema(Schema $schema): voidReturns: void
This method takes a Schema object and converts it to a migration, which is then stored in the $migration property.
Parameters
| Parameter | Type | Description |
|---|---|---|
$schema | Hazaar\DBI\Manager\Schema | the schema to be set |
count
Counts the number of actions in the migration's "up" phase.
public count(): intReturns: int
save
Saves the current migration snapshot to a JSON file in the specified target directory.
public save(Adapter $dbi, string $schemaInfoTable, string $targetDir): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$dbi | Hazaar\DBI\Adapter | |
$schemaInfoTable | string | |
$targetDir | string | the directory where the migration snapshot file will be saved |
getVersion
Retrieves the version information for the snapshot, including migration details.
public getVersion(): VersionReturns: Hazaar\DBI\Manager\Version
compareExtensions
Compares extensions between the master and compare schemas, adding migration actions as needed.
private compareExtensions(Migration $migration, Schema $masterSchama, Schema $compareSchema): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$migration | Hazaar\DBI\Manager\Migration | the migration object to update |
$masterSchama | Hazaar\DBI\Manager\Schema | the master schema to compare against |
$compareSchema | Hazaar\DBI\Manager\Schema | the schema to compare with the master schema |
compareTypes
Compares custom types (ENUMs and composite types) between the master and compare schemas.
private compareTypes(Migration $migration, Schema $masterSchama, Schema $compareSchema): voidReturns: void
New types are created. Types with only appended enum values or composite fields are altered in place. Any other change - a removed, reordered, renamed, or retyped entry - can't be applied with a simple ALTER in PostgreSQL, so the type is instead dropped and recreated; since PostgreSQL CASCADEs that drop to anything using the type, a warning is raised alongside it.
Parameters
| Parameter | Type | Description |
|---|---|---|
$migration | Hazaar\DBI\Manager\Migration | the migration object to update |
$masterSchama | Hazaar\DBI\Manager\Schema | the master schema to compare against |
$compareSchema | Hazaar\DBI\Manager\Schema | the schema to compare with the master schema |
compareTables
Compares the tables between the master schema and the compare schema, and generates the necessary migration actions.
private compareTables(Migration $migration, Schema $masterSchama, Schema $compareSchema): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$migration | Hazaar\DBI\Manager\Migration | the migration object to which the actions will be added |
$masterSchama | Hazaar\DBI\Manager\Schema | the master schema to compare against |
$compareSchema | Hazaar\DBI\Manager\Schema | the schema to compare with the master schema |
compareConstraints
Compares the constraints between the master schema and the schema to be compared.
private compareConstraints(Migration $migration, Schema $masterSchama, Schema $compareSchema): voidReturns: void
If a constraint does not exist in the master schema, it adds a create action to the migration. If a constraint exists but is different, it adds an alter action to the migration.
Parameters
| Parameter | Type | Description |
|---|---|---|
$migration | Hazaar\DBI\Manager\Migration | the migration object to which actions will be added |
$masterSchama | Hazaar\DBI\Manager\Schema | the master schema to compare against |
$compareSchema | Hazaar\DBI\Manager\Schema | the schema to be compared |
compareIndexes
Compares the indexes between the master schema and the schema to be compared,
private compareIndexes(Migration $migration, Schema $masterSchama, Schema $compareSchema): voidReturns: void
and generates the appropriate migration actions.
Parameters
| Parameter | Type | Description |
|---|---|---|
$migration | Hazaar\DBI\Manager\Migration | the migration object to which actions will be added |
$masterSchama | Hazaar\DBI\Manager\Schema | the master schema containing the current state of the database |
$compareSchema | Hazaar\DBI\Manager\Schema | the schema to be compared against the master schema |
compareFunctions
Compares functions between the master and compare schemas, adding migration actions as needed.
private compareFunctions(Migration $migration, Schema $masterSchama, Schema $compareSchema): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$migration | Hazaar\DBI\Manager\Migration | the migration object to update |
$masterSchama | Hazaar\DBI\Manager\Schema | the master schema to compare against |
$compareSchema | Hazaar\DBI\Manager\Schema | the schema to compare with the master schema |
compareTriggers
Compares triggers between the master and compare schemas, adding migration actions as needed.
private compareTriggers(Migration $migration, Schema $masterSchama, Schema $compareSchema): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$migration | Hazaar\DBI\Manager\Migration | the migration object to update |
$masterSchama | Hazaar\DBI\Manager\Schema | the master schema to compare against |
$compareSchema | Hazaar\DBI\Manager\Schema | the schema to compare with the master schema |
compareViews
Compares views between the master and compare schemas, adding migration actions as needed.
private compareViews(Migration $migration, Schema $masterSchama, Schema $compareSchema): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$migration | Hazaar\DBI\Manager\Migration | the migration object to update |
$masterSchama | Hazaar\DBI\Manager\Schema | the master schema to compare against |
$compareSchema | Hazaar\DBI\Manager\Schema | the schema to compare with the master schema |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000