Migrations
Starting with version 2.5, migrations are available in MV. For older versions, you can update the framework and use migrations. You can launch migrations through the console and through the admin panel.
MV offers to perform database structure transformations based on the current state of the models, as well as special settings in the $migrations parameter, which can be added to any model.
To check for migrations via Composer, you need to run the command:
composer mv:migrations
Migrations for creating new fields and tables are created automatically. For other types of migrations, you need to add code to the class of the desired model.
class Pages extends Model
{
...
protected $migrations = [
'add_index' => ['active', 'id, active', 'name'],
'drop_index' => ['parent'],
'drop_column' => ['title'],
'rename_column' => ['content' => 'main_content']
];
}
Migrations for creating new fields and tables are created automatically. For other types of migrations, you need to add code to the class of the desired model.
Notes
1. New models and fields added to the model class are included in migrations automatically, including additional tables for many-to-many fields.
2. The drop_column and rename_column options are available for the SQLite database only in newer versions of PDO.
3. If a field in the model class was commented out or deleted in the code, it will not be included in the migration for deletion.
4. If a field was deleted via the drop_column option but remains in the model class code, the migration will offer to create it again.
5. For many-to-one fields, migrations will offer to create an index in the opposite model to speed up retrieval.
Previous section
System settings