Incremental versions
By default, generate creates incremental versions. The first version is 1.0.0. Each new version adds one to the last number: 1.0.1, 1.0.2 and so on.
To set the version name, use --version:
vendor/bin/phalcon-migrations generate --version=2.0.0A version with fewer than three parts gets zeros. For example, --version=1.1 creates the version 1.1.0.
If the version already exists, the command stops with an error. To overwrite the files of the existing version, add --force.
A version with another name can be the same version, for example 1.0.0.0 and 1.0.0 (see Order of the versions). generate --version=1.0.0.0 next to 1.0.0 stops with the error Version 1.0.0 already exists. With --force, it overwrites the files of 1.0.0.
Order of the versions
The package compares incremental versions part by part, as numbers:
1.0.9 < 1.0.10 < 1.0.11 < 1.1.01.0.0 < 1.0.0.11.0.0and1.0.0.0are the same version. A missing part is0.
run and export stop with an error, before they change the database, in these conditions:
- Two versions are the same version. If they are in two migrations directories, use one configuration for each set of migrations, each with its own log (
--log-tableor--log-path). If they are in one directory, for example1.0.0and1.0.0.0, remove or rename one of the two version directories. - Two versions have the same old order number, for example
1.0.10and1.1.0, and old files make the order unsafe. This is true when both versions have old files. It is also true when only one of the two versions is in the log, and the other version has old files. In version 4.0.1 and earlier, only one of the two versions ran. The error names the two versions. It also names the version that is not in the log, if there is one: that version did not run on this database. Remove the version, or generate it again.
The old order number is the version stamp of the old class names, X * 100 + Y * 10 + Z. See Old migration files.
Timestamp based migrations
Using this approach is useful when more than one developer is participating in the database structure management.
- To generate a timestamp based version, set a description with the
--descroption, or withdescrin the config file.--ts-based, orts-basedin the config file, also creates a timestamp based version, with no description. - To run, list or export timestamp based versions, use
'ts-based' => truein the config file, or the--ts-basedoption.
The description can contain only lowercase letters, digits and underscores (_). If it has other characters, the command stops with an error. For example:
vendor/bin/phalcon-migrations generate --descr=create_usersThe command creates a version directory with a name like this:
* 1582539287636860_create_usersThe name is the current Unix time in microseconds, then _, then the description.
Migrations will be executed from oldest to newest.