Upgrade from 5.x to 6.0
Version 6.0 changes some behavior of version 5.0. To upgrade:
- Rename each incremental version directory with fewer than three parts in its name, for example
1.1to1.1.0. For such a directory,run,list,exportandgeneratestop with an error. See Migration files. - Examine the directories with a version and other text in their name, for example
1.0.0-old. Version 5.0.0 ran them as versions. Now the package skips them with a notice. If such a directory is a version, rename it to its version. - Add
--ts-based(orts-based) to eachgeneratewith a description. In version 5.0.0,--descralone created a timestamp based version thatrun,listandexportdid not see. Now it stops with an error. See Timestamp based migrations. - Examine your descriptions and your
--datavalues.generatestops with an error for a description that is not in the form of the examplecreate_users, and for a--datavalue other thanalwaysoroncreate. In version 5.0.0, a wrong--datavalue created a version with no data. - PostgreSQL: make sure that your migration files have the defaults of the columns. The morph now removes a default of the live column that the file does not have, as on MySQL. See Column options.
- If the project directory has a file with the name
.phalcon, move the file, or setlog-path. In version 5.0.0, the file log deleted the file. Now the action stops with an error. See Migrations log. - Generate again the versions that did not run yet, if their files have the wrong data of some PostgreSQL and SQLite tables. See Files from version 5.0.0 or earlier.
- If your code catches the exception for a
configvalue that is not aConfigobject, examine the message. The new message isThe option config must be an object of Phalcon\Migrations\Utils\Config (Config::fromArray()).Migrations::generate()now also throws this exception. - If your PHP code reads the size of a time column from
listColumns(), expect the precision: the size of aTIMESTAMP,DATETIMEorTIMEcolumn is now its precision, for example0on MySQL and6on PostgreSQL for a column with no precision. - Before the first
run, compare the keys of your migration files with the database, for example withgenerateto another directory. The morph now applies each difference of the column order or the type of an index, and of the actions or the referenced schema of a foreign key. Version 5.0.0 did not see these differences. Generate again the PostgreSQL files that version 5.0.0 or earlier made for tables with indexes of more than one column: the column order of such an index can be wrong in the file. - If your PHP code reads the columns of an index from
listIndexes(), expectnullfor a part of the index on an expression (for examplelower(email));Index::hasExpression()tells you. On PostgreSQL, an index on an expression is now in the list. See Indexes and foreign keys.
Changes you can see
- The morph compares the form in which the database stores each column. A type that the database stores as another type, a size that it does not keep, or an attribute that it does not store (for example
unsignedon PostgreSQL) gives no change at each run, and a rename of such a column keeps its data. - The files of
generatecan change one time.generatethen writes one new version for each changed table:- PostgreSQL: a
FLOATorDOUBLE PRECISIONcolumn isTYPE_DOUBLE(wasTYPE_FLOAT), and aVARCHARwith no length has no size (was1); - SQLite: each column has the type that SQLite stores, with no size (for example
TYPE_TEXTforVARCHARandCHARACTER,TYPE_INTEGERforBIGINTandTINYINT,TYPE_DATETIMEforTIMESTAMP); - MySQL and PostgreSQL: a time column with a precision has its
size, and aCURRENT_TIMESTAMP(n)default or a MySQLON UPDATE CURRENT_TIMESTAMP(n)is in the file; - PostgreSQL: a column with a comment and a default that is an expression has
'defaultExpression' => true; - MySQL and PostgreSQL: a text default with
CURRENT_TIMESTAMPin it (for example'Not CURRENT_TIMESTAMP') is in the file.
- PostgreSQL: a
- The data files (
.dat) ofgenerate --datacan change one time: the rows are in the order of the primary key, a boolean is1or0, and the textNULLis\NULL. The older files load as before. - With
--verbose, the SQL of the database log is also printed. - MySQL with
lower_case_table_names=0(the default on Linux): the compare of two table names keeps the case. A tablePhalcon_Migrationsis not the log tablephalcon_migrations. - SQLite:
--skip-foreign-checksturns offPRAGMA foreign_keysduring the migration, and then puts back the value of before. - The morph applies a change of the column order or the type of an index, and of the actions or the referenced schema of a foreign key. It drops the foreign keys first and adds them last, so the order of the statements with
--verbosechanges. - PostgreSQL: a primary key index with the name
PRIMARYin the file is the primary key<table>_pkeyof the table. A second morph changes nothing. - MySQL: the morph keeps the index that MySQL made for a foreign key, also when the file does not list it, and it changes the columns of a foreign key.
- The primary key of the column flags (
'primary' => true) stays when the file also has a list of indexes. - An index with a part on an expression (for example
lower(email)) is not in the files ofgenerate, which prints a message for it. The morph does not drop or change such an index, also when an older PostgreSQL file lists it as an index on its columns only. generatewith amigrationsDirlist that has a directory that does not exist finds the next version in the other directories. Before, it stopped with an error.
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.