Generate or migrate database changes via migrations.
Main idea of Phalcon migrations is to automatically detect changes and morphing without writing manual migrations.
Phalcon Documentation - Database Migrations
- PHP >= 8.2
- PHP ext-pdo, with the PDO driver of your database (pdo_mysql, pdo_pgsql or pdo_sqlite)
- PHP ext-posix (Linux)
composer require --dev phalcon/migrations
What you need for quick start:
- Configuration file (ex:
migrations.php) in root of your project (you can also pass them as parameters inside CLI environment) - Create database tables structure
- Execute command to generate migrations
After that you can execute that migrations (run) in another environment to create same DB structure.
Configuration filename can be whatever you want.
The file returns a plain array. The .ini and .json formats are also supported, and .yaml and .yml with the PHP yaml extension.
<?php
return [
'database' => [
'adapter' => 'mysql',
'host' => '127.0.0.1',
'username' => 'root',
'password' => '',
'dbname' => 'db-name',
'charset' => 'utf8mb4',
],
'application' => [
'log-in-db' => true,
'no-auto-increment' => true,
'skip-ref-schema' => true,
'skip-foreign-checks' => true,
'migrations' => 'db/migrations',
'ts-based' => true, // true - Use TIMESTAMP as version name, false - use versions
'export-data-from-tables' => [
// Tables names
// Attention! It will export data every new migration
],
],
];vendor/bin/phalcon-migrations generateOr if you have ready to use configuration file.
vendor/bin/phalcon-migrations generate --config=migrations.phpvendor/bin/phalcon-migrations runOr if you have ready to use configuration file.
vendor/bin/phalcon-migrations run --config=migrations.phpvendor/bin/phalcon-migrations list