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-versionfile in the project directory. To use a different file, setlog-pathor--log-path. If the directory of the file does not exist, the package creates it. - Database. Set
log-in-dbtotrue, or use the--log-in-dboption. The log is thephalcon_migrationstable. To use a different table, setlog-tableor--log-table. If the table does not exist, the package creates it. The table has the columnsversion,start_timeandend_time. Whengenerateruns for all the tables, it skips the log table.
The default log
In version 4, the file log is the default. In version 5.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 4.x. 5.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-dbin the configuration,trueorfalse--log-in-dbor--log-in-db=falseon the CLI- The
migrationsInDbkey in a call toMigrations::run(),Migrations::listAll()orMigrations::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:
-
Set
log-in-dbtotruein the configuration. -
Run
import-logfor each database that the file log describes:vendor/bin/phalcon-migrations import-log --config=migrations.php -
Run
listand make sure that the versions are applied. -
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