Skip to content
Bernhard Baumrock edited this page Oct 19, 2022 · 3 revisions

Welcome to the RockMigrations wiki!


See the video here:


See the navigation on the right!

QuickStart

The first thing I always do is to add this to my development config (see here how to manage different configs for dev/live):

$config->rockmigrations = [
  'syncSnippets' => true,
];

This copies the VSCode snippets to the .vscode folder and that makes VSCode show helpful snippets, eg for loading RockMigrations and showing code suggestions:

Then you can simply choose rmf-datetime for example and get the code to use to create your field:

The rm snippet lets you quickly access the RockMigrations module with typehints so that you get proper IntelliSense:

To write your first migrations just put this in your site/migrate.php. The example code uses bd() calls for dumping data. You need TracyDebugger installed!

/** @var RockMigrations $rm */
$rm = $modules->get("RockMigrations");
bd('Create field + template via RM');
$rm->createField('demo', 'text', [
  'label' => 'My demo field',
  'tags' => 'RMDemo',
]);
$rm->createTemplate('demo');
$rm->setTemplateData('demo', [
  'fields' => [
    'title',
    'demo',
  ],
  'tags' => 'RMDemo',
]);

Reload your site and you will see the new field and template in the backend and you'll see the message in the tracy debug bar.

Now do a modules refresh (not a regular page reload) and note that the migration run again (the same message appears in tracy). There are two important things to understand here:

  1. Migrations can run multiple times and will always lead to the same result.
  2. If you put your migrations in ready.php or an autoload module they will run on every request. This not a good idea as it may slow down your site significantly

Now do a regular page reload. The migration will not run as nothing has changed. A modules refresh does always force to run migrations.

Clone this wiki locally