Skip to content

PHP API

Run the actions of the package from PHP code, with the options of each method.

Run migrations from specific migrations directory

<?php

use Phalcon\Migrations\Migrations;
use Phalcon\Migrations\Utils\Config;

$config = Config::fromArray([
    'database' => [
        'adapter'  => 'mysql',
        'host'     => 'phalcon-db-mysql',
        'username' => 'root',
        'password' => 'root',
        'dbname'   => 'vokuro',
    ],
]);

Migrations::run([
    'directory'      => __DIR__,
    'migrationsDir'  => [
        __DIR__ . '/migrations',
    ],
    'config'         => $config,
    'migrationsInDb' => true,
]);

The config value must be a Phalcon\Migrations\Utils\Config object. Use Config::fromArray() to create it from an array with the database and application sections. If you use a plain array, Migrations::run() throws an exception with the message Internal error. Config should be an instance of Phalcon\Migrations\Utils\Config.

Migrations::run() does not read the log-in-db key of the configuration. Use the migrationsInDb key.

Migrations::run() accepts these options:

Key Type Description
config Config Database configuration (required)
migrationsDir array / string Migrations directories (required)
directory string Project directory, which holds the file log. Default: the BASE_PATH constant, or the parent directory of APP_PATH. Set it if you do not define these constants
version string Version to migrate to. Default: the latest version
tableName string Table name, comma-separated table names or a prefix with an asterisk. Default: @ (all tables)
tsBased bool true - use timestamp based versions
migrationsInDb bool true - keep the migrations log in the database. false - keep it in a file. If you do not set it, the package uses the file log and gives a deprecation notice
log-path string Path of the log file (file log). Default: .phalcon/migration-version in the project directory
log-table string Name of the log table (database log). Default: phalcon_migrations
verbose bool true - show debugging information
skip-foreign-checks bool true - disable the foreign key checks during the run
truncate bool true - empty each table before batchInsert() imports its data
Navigation

Type to search…

↑↓ navigate↵ selectEsc close