PHPackages                             thathoff/kirby-migrations - 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. [Database &amp; ORM](/categories/database)
4. /
5. thathoff/kirby-migrations

ActiveKirby-plugin[Database &amp; ORM](/categories/database)

thathoff/kirby-migrations
=========================

Migrate content or databases when deploying your Kirby project

v1.1.1(5mo ago)17758↓86.7%1MITPHPCI passing

Since Apr 30Pushed 5mo ago3 watchersCompare

[ Source](https://github.com/thathoff/kirby-migrations)[ Packagist](https://packagist.org/packages/thathoff/kirby-migrations)[ RSS](/packages/thathoff-kirby-migrations/feed)WikiDiscussions main Synced today

READMEChangelog (5)Dependencies (5)Versions (6)Used By (0)

Kirby Migrations
================

[](#kirby-migrations)

[![Screenshot of the terminal running a migration.](./.github/screenshot.png)](./.github/screenshot.png)

This plugin provides commands to [Kirby CLI](https://github.com/getkirby/cli) for simple migrations.

Use cases are **database migrations** for your SQL database, **migrating content** or **creating pages** when deploying your Kirby page. See the [examples](#examples) section for more details.

You can also create migrations for your own plugins. See the [Migrations for Plugins](#migrations-for-plugins) section for more details.

Kirby CLI
---------

[](#kirby-cli)

This plugin uses the [Kirby CLI](https://github.com/getkirby/cli) to run migrations. Either use it via composer (this plugin will install it for you) or install it globally.

```
# not required, but will install the CLI globally
composer global require getkirby/cli
```

If you installed it globally, you can run the migrations via `kirby migrations:apply` otherwise use `./vendor/bin/kirby migrations:apply`. In the following, we will assume you’re using it via composer.

Configuration
-------------

[](#configuration)

This plugin provides the following configuration options:

- `thathoff.migrations.dir`: The directory where the migrations are stored. Defaults to a `migrations` folder inside the Kirby `site` directory.
- `thathoff.migrations.stateFile`: The file where the state of the migrations is stored. Defaults to a `.migrations` file inside the `migrations` directory.

Usage
-----

[](#usage)

### Create a New Migration

[](#create-a-new-migration)

This will create a new migration file in the `migrations` directory.

```
./vendor/bin/kirby migrations:create
```

### Apply All Pending Migrations

[](#apply-all-pending-migrations)

This will apply all pending migrations. When using the `-f` or `--force` flag, it will apply the migrations without asking for confirmation (eg. for CI/CD pipelines).

```
./vendor/bin/kirby migrations:apply [-f|--force]
```

### Show Status

[](#show-status)

This will show the status of the migrations.

```
./vendor/bin/kirby migrations:status
```

### Rollback the Last Batch of Migrations

[](#rollback-the-last-batch-of-migrations)

This will rollback the last batch of migrations. When using the `-f` or `--force` flag, it will rollback the migrations without asking for confirmation.

```
./vendor/bin/kirby migrations:rollback [-f|--force]
```

Migrations for Plugins
----------------------

[](#migrations-for-plugins)

Plugins can also have their own migrations. To support migrations in your plugin, you need to create a `migrations`folder in your plugin's root directory and enable migrations in your plugin's `index.php` file by setting the `migrations` option to `true`.

```
use Kirby\Cms\App as Kirby;

Kirby::plugin('example/test', [
    'migrations' => true,
]);
```

To use a different path, you can set the `migrations` option to the path to the migrations directory:

```
use Kirby\Cms\App as Kirby;

Kirby::plugin('example/test', [
    'migrations' => __DIR__ . '/classes/migrations',
]);
```

After this, you can create migrations for your plugin by using the `migrations:create` command and specifying the plugin ID (in the example above it’s `example/test`) as the second argument.

It’s recommended to prefix your migration names with your plugins name to avoid conflicts with other plugins as all migrations are created in the same namespace.

```
./vendor/bin/kirby migrations:create
```

All other commands will automatically detect the plugin migrations and apply them accordingly.

Examples
--------

[](#examples)

All database examples assume you have a [database configured](https://getkirby.com/docs/guide/database#database-connection) in your `config.php` file.

### Create a Table in a Database

[](#create-a-table-in-a-database)

```
./vendor/bin/kirby migrations:create InitDb
```

```
