phalcon / migrations

Generate or migrate database changes via migrations.
https://docs.phalcon.io/latest/en/db-migrations
BSD 3-Clause "New" or "Revised" License
28 stars 23 forks source link
database database-migrations db-migration migration-tool migrations phalcon phalcon-php

Phalcon Migrations

Discord Packagist Version PHP from Packagist codecov Packagist

Generate or migrate database changes via migrations.
Main idea of Phalcon migrations is to automatically detect changes and morphing without writing manual migrations.

Full documentation

Phalcon Documentation - Database Migrations

Requirements

Installing via Composer

composer require --dev phalcon/migrations

Quick start

What you need for quick start:

After that you can execute that migrations (run) in another environment to create same DB structure.

Create configuration file

Configuration filename can be whatever you want.

<?php

use Phalcon\Config;

return new Config([
    'database' => [
        'adapter' => 'mysql',
        'host' => '127.0.0.1',
        'username' => 'root',
        'password' => '',
        'dbname' => 'db-name',
        'charset' => 'utf8',
    ],
    'application' => [
        'logInDb' => true,
        'no-auto-increment' => true,
        'skip-ref-schema' => true,
        'skip-foreign-checks' => true,
        'migrationsDir' => 'db/migrations',
        'migrationsTsBased' => true, // true - Use TIMESTAMP as version name, false - use versions
        'exportDataFromTables' => [
            // Tables names
            // Attention! It will export data every new migration
        ],
    ],
]);

Generate migrations

vendor/bin/phalcon-migrations generate

Or if you have ready to use configuration file.

vendor/bin/phalcon-migrations generate --config=migrations.php

Run migrations

vendor/bin/phalcon-migrations run

Or if you have ready to use configuration file.

vendor/bin/phalcon-migrations run --config=migrations.php

List existing migrations

vendor/bin/phalcon-migrations list