|
2 | 2 |
|
3 | 3 | Migrations are PHP classes that make one-time changes to the system. |
4 | 4 |
|
5 | | -For the most part, migrations in Craft work similarly to [Yii’s implementation](https://www.yiiframework.com/doc/guide/2.0/en/db-migrations), but unlike Yii, Craft manages three different types of migrations: |
| 5 | +For the most part, migrations in Craft work similarly to [Yii’s implementation](guide:db-migrations). _Unlike_ Yii, Craft manages three different types of migrations: |
6 | 6 |
|
7 | | -- **App migrations** – Craft’s own internal migrations. |
8 | | -- **Plugin migrations** – Each installed plugin has its own migration track. |
9 | | -- **Content migrations** – Your Craft project itself can have migrations, too. |
| 7 | +App migrations |
| 8 | +: Craft’s own internal migrations. You will only create an `app` migration when contributing to Craft. Every Craft installation runs these migrations after an update. |
10 | 9 |
|
11 | | -## Creating Migrations |
12 | | - |
13 | | -::: tip |
14 | | -If your Craft install is running from a Vagrant box, you will need to SSH into the box to run these commands. |
15 | | -::: |
| 10 | +Plugin migrations |
| 11 | +: Each installed plugin has its own migration “track.” Only Craft projects that have your plugin installed and enabled will run these migrations. |
16 | 12 |
|
17 | | -To create a new migration for your plugin or project, open up your terminal and go to your Craft project: |
| 13 | +Content migrations |
| 14 | +: Migrations specific to your Craft project. These often contain steps that manipulate data based on handles or other identifiers that are only relevant internally. |
18 | 15 |
|
19 | | -```bash |
20 | | -cd /path/to/project |
21 | | -``` |
| 16 | +## Creating Migrations |
22 | 17 |
|
23 | | -Then run the following command to generate a new migration file for your plugin or project: |
| 18 | +To create a new migration, use the `migrate/create` command: |
24 | 19 |
|
25 | 20 | ::: code |
26 | | - |
27 | 21 | ```bash Plugin Migration |
28 | 22 | php craft migrate/create my_migration_name --plugin=my-plugin-handle |
29 | 23 | ``` |
30 | | - |
31 | 24 | ```bash Content Migration |
32 | 25 | php craft migrate/create my_migration_name |
33 | 26 | ``` |
34 | | - |
35 | 27 | ::: |
36 | 28 |
|
37 | | -Enter `yes` at the prompt, and a new migration file will be created for you. You can find it at the file path output by the command. |
| 29 | +Enter `yes` at the prompt, and a new migration file will be created for you. You can find it at the file path output by the command; migration classes include a timestamp prefix with the format `mYYMMDD_HHMMSS`, like `m250923_000000`. |
38 | 30 |
|
39 | | -If this is a plugin migration, increase your plugin’s [schema version](craft5:craft\base\PluginTrait::$schemaVersion), so Craft knows to check for new plugin migrations as people update to your new version. |
| 31 | +This file and class should _never_ be renamed after release! Doing so can cause it to run again, or out of order. |
| 32 | + |
| 33 | +::: tip |
| 34 | +If this is a plugin migration, increase your plugin’s [schema version](craft5:craft\base\PluginTrait::$schemaVersion), so Craft knows to check for new plugin migrations after an update. |
| 35 | +::: |
40 | 36 |
|
41 | 37 | ### What Goes Inside |
42 | 38 |
|
|
0 commit comments