PHPackages                             baumrock/rockmigrations - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. baumrock/rockmigrations

ActiveProcesswire-module

baumrock/rockmigrations
=======================

v7.4.1(1mo ago)46542↑190.3%14MITPHPCI passing

Since Oct 29Pushed 2w ago2 watchersCompare

[ Source](https://github.com/baumrock/RockMigrations)[ Packagist](https://packagist.org/packages/baumrock/rockmigrations)[ RSS](/packages/baumrock-rockmigrations/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (3)Versions (111)Used By (0)

[![](logo.svg)](logo.svg)

See the video here:

[![](thumb.png)](https://www.youtube.com/watch?v=eBOB8dZvRN4)
[![](thumb2.png)](https://www.youtube.com/watch?v=o6O859d3cFA)

### Module Description

[](#module-description)

RockMigrations has an easy API to do all the things you can do in the PW backend via code. This means you can **fully version control your site** or app simply by adding all the necessary fields and templates not via clicking but via writing simple scripts that do that tasks for you.

The module also contains several helpers that make it extremely easy to implement **fully automated CI/CD pipelines**.

Wiki
====

[](#wiki)

Check out the [WIKI for a Quickstart and Docs](https://github.com/baumrock/RockMigrations/wiki)!

Pro-Fields and 3rd-Party-Fields
-------------------------------

[](#pro-fields-and-3rd-party-fields)

While RockMigrations efficiently handles most database schema changes, it's worth mentioning that not all ProcessWire pro-fields or 3rd-party-fields might be covered. In case of unsupported fields, users have the choice to sponsor the addition of support or opt for manual migration using traditional methods, mimicking a scenario without RockMigrations. This approach guarantees versatility for different field types within the ProcessWire CMS ecosystem.

Also don't forget that you can still use the PW API for everything you need or want even if you are using RockMigrations. That means you can use RockMigrations for everything that it supports (which is maybe 99% of what anybody needs) and just use the plain PW API for the remaining 1% or even make those changes manually if that is an option.

Where do I find out all those field and template properties?
------------------------------------------------------------

[](#where-do-i-find-out-all-those-field-and-template-properties)

1. You can edit your field or template and copy the code from there (I recommend to only copy the settings you need to make your migration files more readable): [![img](https://camo.githubusercontent.com/0f3e52bc60932aca7c5e1d4427894e1dcac2b8ee466c867e98189ba20b10099e/68747470733a2f2f692e696d6775722e636f6d2f4941485633565a2e706e67)](https://camo.githubusercontent.com/0f3e52bc60932aca7c5e1d4427894e1dcac2b8ee466c867e98189ba20b10099e/68747470733a2f2f692e696d6775722e636f6d2f4941485633565a2e706e67)
2. Hover the caret on the very right of the field of the setting you want to set: [![img](https://camo.githubusercontent.com/a93b8eca296049a4a4098388485eb2ee27a03f11324dfcbbfdb8cc06704f9872/68747470733a2f2f692e696d6775722e636f6d2f686d79647a66352e706e67)](https://camo.githubusercontent.com/a93b8eca296049a4a4098388485eb2ee27a03f11324dfcbbfdb8cc06704f9872/68747470733a2f2f692e696d6775722e636f6d2f686d79647a66352e706e67)

Magic
-----

[](#magic)

RockMigrations does not only help you with your migrations and deployments but it also adds a lot of helpers that make developing with ProcessWire even more fun.

See WIKI for MagicPages!

### Snippets

[](#snippets)

Another option that helps you get started with migration syntax is using the shipped VSCode snippets. I highly recommend enabling the `syncSnippets` option in your config:

```
// site/config.php
$config->rockmigrations = [
  "syncSnippets" => true,
];
```

Watching files, paths or modules
--------------------------------

[](#watching-files-paths-or-modules)

RockMigrations can watch files, paths and modules for changes. It will detect changes on any of the files on the watchlist and trigger migrations to run if anything changed.

As from version 1.0.0 (29.8.2022) RockMigrations will not run all migrations if one file changes but will only migrate this single changed file. This makes the migrations run a lot faster!

When run from the CLI it will still run every single migration file to make sure that everything works as expected and no change is missed.

Sometimes it is necessary that even unchanged files are migrated. RockMatrix is an example for that, where the module file triggers the migrations for all Matrix-Blocks. In that case you can add the file to the watchlist using the `force` option:

```
// inside RockMatrix::init
$rm->watch($this, true, ['force'=>true]);
```

### Watching modules

[](#watching-modules)

You can easily watch any ProcessWire module for changes and trigger the `migrate()` method whenever the file is changed:

```
// module needs to be autoload!
public function init() {
  $rm = $this->wire->modules->get('RockMigrations');
  if($rm) $rm->watch($this);
}
public function migrate() {
  bd('Migrating MyModule...');
}
```

### Watching files

[](#watching-files)

You can watch single files or entire paths:

```
$rm->watch(__FILE__, false);
$rm->watch(__DIR__."/foo");
```

Note that you need to define `FALSE` as second parameter if the file should not be migrated but only watched for changes. If you set it to `TRUE` the file will be included and executed as if it was a migration script (see examples below).

Running migrations
------------------

[](#running-migrations)

RockMigrations will run migrations automatically when a watched file was changed. In case you want to trigger the migrations manually (eg after deployment) you can use the `migrate.php` file:

```
php site/modules/RockMigrations/migrate.php
```

Sometimes you want to work on a file and you want it to be watched for changes, but you don't want to trigger the migrations all the time. For example when working on markup or LESS. In that case you can disable automatic running of migrations:

```
$config->noMigrate = true;
```

This prevents running migrations but files will still be watched for changes and you will still be able to trigger migrations from the CLI.

### Hooking after migrationsDone

[](#hooking-after-migrationsdone)

If you want to apply migrations after all other migrations have run, you can hook after `migrationsDone`:

```
$wire->addHookAfter("RockMigrations::migrationsDone", function(HookEvent $event) {
  /** @var RockMigrations $rm */
  $rm = $event->object;
  $rm->removeFieldFromTemplate('title', 'field-profilephoto');
  $rm->removeFieldFromTemplate('title', 'field-pressphoto');
});
```

Files On Demand
---------------

[](#files-on-demand)

You can instruct RockMigrations to download files on demand from a remote server. This makes it possible to create content on the remote system (eg on the live server), pull data from the database to your local machine and as soon as you open a page RockMigrations will fetch the missing files from your remote server.

```
// without authentication
$config->filesOnDemand = 'https://example.com';

// with http basic authentication
$config->filesOnDemand = 'https://user:password@example.com';
```

#### YAML

[](#yaml)

```
$rm->watch("/your/file.yaml");
```

```
fields:
  foo:
    type: text
    label: My foo field
```

#### PHP

[](#php)

```
$rm->watch("/your/file.php");
```

```
