Download the PHP package peptolab/phpdb-migration without Composer
On this page you can find all versions of the php package peptolab/phpdb-migration. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package phpdb-migration
phpdb-migration
Idempotent database migration engine for php-db/phpdb.
Features
- Idempotent migrations - Safe to run multiple times; operations check schema state before executing
- Definition mismatch detection - Compare existing schema against desired definitions with configurable strategies (ignore, report, alter)
- Rich helper methods -
ensureTable(),ensureColumn(),ensureIndex(),ensureForeignKey(),ensureUniqueKey(), and more - Dry-run preview - See what SQL would execute without making changes
- CLI commands -
db:migrateanddb:migrate:createvia Symfony Console - Laminas/Mezzio integration - ConfigProvider for container-based setup with laminas-cli
Installation
Quick Start
Standalone Usage
Laminas/Mezzio Integration
The package auto-registers via the ConfigProvider. Add your configuration:
Configuration
| Key | Type | Default | Description |
|---|---|---|---|
migrations_path |
string |
getcwd() . '/data/migrations' |
Directory containing migration files |
migrations_namespace |
string |
App\Migration |
PSR-4 namespace of migration classes |
adapter_service |
string |
PhpDb\Adapter\AdapterInterface |
Container service name for the adapter |
resolution |
MismatchStrategy\|string |
MismatchStrategy::Report |
How to handle definition mismatches |
Writing Migrations
Create a migration class that extends AbstractMigration:
Available Helper Methods
Schema Creation
ensureTable(string $table, callable $callback)- Create table if not exists; validates definition if existsensureColumn(string $table, ColumnInterface $column)- Add column if not exists; validates if existsensureIndex(string $table, string $name, array $columns, bool $unique = false)- Add index if not existsensureUniqueKey(string $table, string $name, array $columns)- Add unique constraint if not existsensureForeignKey(string $table, string $name, string $col, string $refTable, string $refCol, string $onDelete, string $onUpdate)- Add FK if not exists
Schema Removal
dropTableIfExists(string $table)dropColumnIfExists(string $table, string $column)dropIndexIfExists(string $table, string $index)dropForeignKeyIfExists(string $table, string $constraint)
Data & Raw SQL
executeSql(string $sql, ?string $description)- Execute raw SQLexecuteSqlIf(bool $condition, string $sql, ?string $description, ?string $skipMessage)- Conditional SQLmodifyColumn(string $table, string $column, Column $column, ?string $newName)- ALTER columninsertRow(string $table, array $data)- Insert a rowinsertRowIfNotExists(string $table, array $data, array $uniqueColumns)- Conditional insert
Mismatch Strategy
When an ensure* method finds an existing schema object, the mismatch strategy determines what happens:
| Strategy | Behavior |
|---|---|
MismatchStrategy::Ignore |
Skip silently (original behavior) |
MismatchStrategy::Report |
Log mismatch details in MigrationResult::$mismatches |
MismatchStrategy::Alter |
Auto-ALTER the schema to match the desired definition |
Mismatches are tracked per migration and include: table name, column/constraint name, field that differs, expected value, and actual value.
CLI Commands
db:migrate
Run pending database migrations.
Options:
--status, -s- Show migration status--dry-run- Preview SQL without executing--force, -f- Skip confirmation prompt--resolution-strategy, -r- Override mismatch strategy (ignore,report,alter)
db:migrate:create
Create a new migration file.
This generates a timestamped migration file in the configured migrations directory.
Requirements
- PHP 8.3+
- MySQL 8.0.16+ (required for
DROP CONSTRAINTsyntax used bydropForeignKeyIfExists())
Examples
See the docs/examples directory for complete migration examples.
License
BSD-3-Clause. See LICENSE.