Skip to content

Migrations Log

How the package records the versions that it applies: the file log and the database log.

The package records each version that it applies. It uses the log to find the versions to run, and to show the status in list.

  • File. The log is the .phalcon/migration-version file in the project directory. To use a different file, set log-path or --log-path. If the directory of the file does not exist, the package creates it.
  • Database. Set log-in-db to true, or use the --log-in-db option. The log is the phalcon_migrations table. To use a different table, set log-table or --log-table. If the table does not exist, the package creates it. The table has the columns version, start_time and end_time. When generate runs for all the tables, it skips the log table.

If you do not set log-path, and .phalcon in the project directory is a file, the file log cannot use the directory. The action stops with this error, and the file does not change:

The file log needs the folder '/var/www/shop/.phalcon', but it is a file. Move the file, or set the option log-path

The default log

In version 5, the file log is the default. In version 6.0, the database log becomes the default.

If no setting chooses the log, run, list and clean give this PHP deprecation notice:

The file log is the default in 5.x. 6.0 uses the database log. Set log-in-db (migrationsInDb in PHP) to true, then run import-log, or set it to false to keep the file log.

To stop the notice, choose the log with one of these settings:

  • log-in-db in the configuration, true or false
  • --log-in-db or --log-in-db=false on the CLI
  • The migrationsInDb key in a call to Migrations::run(), Migrations::listAll() or Migrations::clean()

Move the file log to the database

The import-log action copies the versions of the file log into the log table of the database. It does this one time, for a new log table.

To move a project to the database log:

  1. Set log-in-db to true in the configuration.

  2. Run import-log for each database that the file log describes:

    vendor/bin/phalcon-migrations import-log --config=migrations.php
  3. Run list and make sure that the versions are applied.

  4. Delete the file log.

import-log uses the database of the configuration, and the file log and the log table of your settings (log-path and log-table, or the defaults). It puts all the versions in one transaction. The start_time and end_time values are the time of the import. The file log does not change.

import-log stops with an error, and changes nothing, in these conditions:

  • The log table has a line.
  • The database has no table other than the log table. The file log cannot describe an empty database.
  • The file log does not exist, or has no version.

When you use the database log, run stops before it changes the database if all these conditions are true:

  • The log table is empty.
  • The file log has versions.
  • The database has a table other than the log table.

The error is:

The log table '<table>' is empty, but the file log '<file>' has <N> versions. If the file is the log of this log table, run import-log. If not, delete or rename the file.

This stops run from applying all the versions again on a database that already has the tables. On an empty database, run applies all the versions as usual. The empty database can be a new database, or a database after clean --force.

Migrations::importLog() does the same in PHP. It accepts the config, directory, log-path and log-table keys.

Many databases

To keep the migrations of more than one database, use one configuration file for each database.

  • With the file log, give each configuration its own log-path.
  • With the database log, each database has its own log table.
  • For two sets of migrations in one database, give each set its own log-table.
vendor/bin/phalcon-migrations run --config=config/main.php
vendor/bin/phalcon-migrations run --config=config/reports.php
Navigation

Type to search…

↑↓ navigate↵ selectEsc close