Upgrade from 4.x to 5.0
Version 5.0.0 changes some behavior of version 4. To upgrade:
- Use the new names of the configuration keys, and
--export-data-from-tablesin place of--exportDataFromTables. The old names give a PHP deprecation notice. Version 6.0 removes them. See Application options. - Choose the migrations log with
log-in-db. Version 6.0 makes the database log the default. To move to the database log, runimport-log. See Migrations log. - Examine your scripts. A CLI option now wins over the configuration for each setting, also
--descr. - MySQL: the connection uses the
utf8mb4character set. In version 4, it usedutf8. To keeputf8, setcharsetin thedatabasesection. See Database options. - Generate again the versions that did not run yet, if their files do not have all the data of the table. See Files from version 4.0.1 or earlier.
- Make sure that your migration files have the comments of the columns. The morph now compares the comment. A column with no comment in the file loses the comment of the live column.
- Examine your incremental versions.
runandexportcan stop with an error for two versions with the same old order number. See Order of the versions. - Remove
--dryfromrun. In version 4,run --dryran the migrations. Now it stops with an error. - Examine the boolean keys of the configuration that have a text value. A text such as
"false"or"off"is nowfalse. In version 4, it wastrue.
The first generate after the update creates a version, because the format of the generated files changed. The old files run as before. See Old migration files.
If your code uses the classes of the package, also examine these changes:
Config::$logInDbisnullwhen the configuration does not setlog-in-db. In version 4, it wasfalse.Generate::getEntity()gives only the header of the file: thedeclareline, the namespace and theuselines. UseGenerate::getCode()for the text of the file.
Upgrade from 3.x to 4.0
Version 4.0.0 removes the dependency on the Phalcon extension. To upgrade:
- Use PHP 8.2 or later.
- Change your PHP configuration file to return an array. See Create the configuration file.
- If you call
Migrations::run()in your code, useConfig::fromArray()for theconfigoption. See Usage example. - Update your migration files with the
migrate-filescommand.
First, see the files that the command changes:
vendor/bin/phalcon-migrations migrate-files --migrations=db/migrations --dry-runThen change the files:
vendor/bin/phalcon-migrations migrate-files --migrations=db/migrations--dry-run=false is the same as no --dry-run: the command changes the files.
The --migrations option is required. The path is relative to the current directory. The command reads all the .php files in the directory and its subdirectories, and replaces these lines:
| Old line | New line |
|---|---|
use Phalcon\Db\Column; |
use Phalcon\Migrations\Db\Column; |
use Phalcon\Db\Index; |
use Phalcon\Migrations\Db\Index; |
use Phalcon\Db\Reference; |
use Phalcon\Migrations\Db\Reference; |
Migration files that you do not update continue to work if the Phalcon\Db classes are available, for example from the Phalcon extension. The package converts the Phalcon\Db\Column, Phalcon\Db\Index and Phalcon\Db\Reference objects when the migration runs.