Snapshot
Snapshot
Represents a database schema snapshot, including version, comment, and migration details.
class Snapshot extends \Hazaar\DBI\Manager\StructProvides methods for creating, comparing, setting, saving, and retrieving schema snapshots and migrations.
Properties
version
The version information for the snapshot.
public Version $versioncomment
The comment associated with the snapshot.
public string $commentmigration
The migration object associated with the snapshot.
public Migration $migrationMethods
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): selfParameters
| 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): ?MigrationThis 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 | Schema | |
$compareSchema | Schema |
setSchema
Sets the schema for the snapshot.
public setSchema(Schema $schema): voidThis method takes a Schema object and converts it to a migration, which is then stored in the $migration property.
Parameters
| Parameter | Type | Description |
|---|---|---|
$schema | Schema | the schema to be set |
count
Counts the number of actions in the migration's "up" phase.
public count(): intsave
Saves the current migration snapshot to a JSON file in the specified target directory.
public save(Adapter $dbi, string $schemaInfoTable, string $targetDir): boolParameters
| Parameter | Type | Description |
|---|---|---|
$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(): VersioncompareExtensions
Compares extensions between the master and compare schemas, adding migration actions as needed.
private compareExtensions(Migration $migration, Schema $masterSchama, Schema $compareSchema): voidParameters
| Parameter | Type | Description |
|---|---|---|
$migration | Migration | the migration object to update |
$masterSchama | Schema | the master schema to compare against |
$compareSchema | 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): voidParameters
| Parameter | Type | Description |
|---|---|---|
$migration | Migration | the migration object to which the actions will be added |
$masterSchama | Schema | the master schema to compare against |
$compareSchema | 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): voidIf 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 | Migration | the migration object to which actions will be added |
$masterSchama | Schema | the master schema to compare against |
$compareSchema | 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): voidand generates the appropriate migration actions.
Parameters
| Parameter | Type | Description |
|---|---|---|
$migration | Migration | the migration object to which actions will be added |
$masterSchama | Schema | the master schema containing the current state of the database |
$compareSchema | 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): voidParameters
| Parameter | Type | Description |
|---|---|---|
$migration | Migration | the migration object to update |
$masterSchama | Schema | the master schema to compare against |
$compareSchema | 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): voidParameters
| Parameter | Type | Description |
|---|---|---|
$migration | Migration | the migration object to update |
$masterSchama | Schema | the master schema to compare against |
$compareSchema | 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): voidParameters
| Parameter | Type | Description |
|---|---|---|
$migration | Migration | the migration object to update |
$masterSchama | Schema | the master schema to compare against |
$compareSchema | Schema | the schema to compare with the master schema |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:24 +0000