PHPackages                             pinkcrab/perique-migration - 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. [Framework](/categories/framework)
4. /
5. pinkcrab/perique-migration

ActiveLibrary[Framework](/categories/framework)

pinkcrab/perique-migration
==========================

A module for the Perique Framework which makes use of the PinkCrab Table Builder and PinkCrab Migration libraries.

2.1.0(2mo ago)01.2k[4 PRs](https://github.com/Pink-Crab/Perique_Migrations/pulls)MITPHPPHP &gt;=8.0.0CI passing

Since Dec 8Pushed 2mo agoCompare

[ Source](https://github.com/Pink-Crab/Perique_Migrations)[ Packagist](https://packagist.org/packages/pinkcrab/perique-migration)[ Docs](https://pinkcrab.co.uk)[ RSS](/packages/pinkcrab-perique-migration/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (4)Dependencies (15)Versions (31)Used By (0)

[![logo](./.github/Perique%20Migrations%20Card.jpg "PinkCrab Perique Migrations")](./.github/Perique%20Migrations%20Card.jpg)

Perique - Migrations
====================

[](#perique---migrations)

A wrapper around various PinkCrab libraries which make it easier to run DB migrations from a plugin created using the Perique Framework.

[![Latest Stable Version](https://camo.githubusercontent.com/39e128e4ab3f076ce2e11c220dae86c4030601e15f0804d8fd98021b390d0a7a/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f706572697175652d6d6967726174696f6e2f76)](https://packagist.org/packages/pinkcrab/perique-migration) [![Total Downloads](https://camo.githubusercontent.com/8c448323253330a633e45bc04d596abca22885ab9a32960ffed67360624f90a0/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f706572697175652d6d6967726174696f6e2f646f776e6c6f616473)](https://packagist.org/packages/pinkcrab/perique-migration) [![Latest Unstable Version](https://camo.githubusercontent.com/dc09be3490d989dcf1bced37ab99380d10ae31336813b460b488561e748ee95e/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f706572697175652d6d6967726174696f6e2f762f756e737461626c65)](https://packagist.org/packages/pinkcrab/perique-migration) [![License](https://camo.githubusercontent.com/ce17166f501241f561b10bdc71d5aa0fb1390c5fa9cb1d708353f14ac9c15a42/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f706572697175652d6d6967726174696f6e2f6c6963656e7365)](https://packagist.org/packages/pinkcrab/perique-migration) [![PHP Version Require](https://camo.githubusercontent.com/1c9922993e17ebdfb831aba5361604aa57500129b9b644b6c924d0c63f678705/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f706572697175652d6d6967726174696f6e2f726571756972652f706870)](https://packagist.org/packages/pinkcrab/perique-migration)[![GitHub contributors](https://camo.githubusercontent.com/ec280343f7b22704d0df6086914cc662bbc8cab8f5b6bba95c26f555ffdd1158/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f50696e6b2d437261622f506572697175655f4d6967726174696f6e733f6c6162656c3d436f6e7472696275746f7273)](https://camo.githubusercontent.com/ec280343f7b22704d0df6086914cc662bbc8cab8f5b6bba95c26f555ffdd1158/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f50696e6b2d437261622f506572697175655f4d6967726174696f6e733f6c6162656c3d436f6e7472696275746f7273)[![GitHub issues](https://camo.githubusercontent.com/94cd0f633474e56141369b6d6f732deae3ca32a82f65486d150e17e6c17faeae/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f50696e6b2d437261622f506572697175655f4d6967726174696f6e73)](https://camo.githubusercontent.com/94cd0f633474e56141369b6d6f732deae3ca32a82f65486d150e17e6c17faeae/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f50696e6b2d437261622f506572697175655f4d6967726174696f6e73)[![WordPress 6.6 Test Suite [PHP8.0-8.4]](https://github.com/Pink-Crab/Perique_Migrations/actions/workflows/WP_6_6.yaml/badge.svg)](https://github.com/Pink-Crab/Perique_Migrations/actions/workflows/WP_6_6.yaml)[![WordPress 6.7 Test Suite [PHP8.0-8.4]](https://github.com/Pink-Crab/Perique_Migrations/actions/workflows/WP_6_7.yaml/badge.svg)](https://github.com/Pink-Crab/Perique_Migrations/actions/workflows/WP_6_7.yaml)[![WordPress 6.8 Test Suite [PHP8.0-8.4]](https://github.com/Pink-Crab/Perique_Migrations/actions/workflows/WP_6_8.yaml/badge.svg)](https://github.com/Pink-Crab/Perique_Migrations/actions/workflows/WP_6_8.yaml)[![WordPress 6.9 Test Suite [PHP8.0-8.4]](https://github.com/Pink-Crab/Perique_Migrations/actions/workflows/WP_6_9.yaml/badge.svg)](https://github.com/Pink-Crab/Perique_Migrations/actions/workflows/WP_6_9.yaml)[![codecov](https://camo.githubusercontent.com/c5f5c6aff431788652b9a6db3f544964e219313488ee5a9929f7ddef3adaa0e4/68747470733a2f2f636f6465636f762e696f2f67682f50696e6b2d437261622f506572697175652d526f7574652f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d34794563654961534650)](https://codecov.io/gh/Pink-Crab/Perique-Route)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/242a8dbf6b0f891af904722a07b3bd48654dcb9da20de45f47912d3e2c060c28/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f50696e6b2d437261622f506572697175655f4d6967726174696f6e732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Pink-Crab/Perique_Migrations/?branch=master)[![Maintainability](https://camo.githubusercontent.com/70a49c3b52574fab7d2f92b2b3481507856bcfc3e0f5ecdf5e032c9216a1097b/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f35653939636139306533353961363438303965632f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/Pink-Crab/Perique_Migrations/maintainability)

---

Why?
====

[](#why)

There already exists a WPDB Migrations system written by PinkCrab for use in any WordPress plugin or even theme. However working this into Perique required building a small little isolated workflow due to the nature of how the Perique Registration Process works and how WordPress handles plugin events such as Activation, Deactivation and Uninstalling.

So to make it more seamless adding Database Migrations to Perique, we have created this library to help.

Depends on
----------

[](#depends-on)

As mentioned this library acts more of a bridge for the following packages.

- [WPDB Migrations](https://github.com/Pink-Crab/WP_DB_Migration)
- [WPDB Table Builder](https://github.com/Pink-Crab/WPDB-Table-Builder)
- [Perique Plugin Life Cycle](https://github.com/Pink-Crab/Perique_Plugin_Life_Cycle)

---

Setup
=====

[](#setup)

```
$ composer require pinkcrab/perique-migrations
```

### Creation of Migrations

[](#creation-of-migrations)

To create database migrations, the `Migration` abstract class must be extended.

> [Full Migration model references below](#migration-model)[Example Plugin](https://github.com/gin0115/Perique_Migrations_Example)

```
class Acme_Migration extends Migration {

    /**
     * Returns the name of the table.
     *
     * @required
     * @return string Table name
     */
    protected function table_name(): string {
        return 'acme_migration_sample_table';
    }

    /**
     * Defines the schema for the migration.
     *
     * @param Schema $schema_config
     * @return void
     */
    public function schema( Schema $schema_config ): void {
        $schema_config->column( 'id' )
            ->unsigned_int( 11 )
            ->auto_increment();

        $schema_config->column( 'user_ref' )
            ->text( 11 );

        $schema_config->column( 'thingy_ref' )
            ->int( 11 );

        $schema_config->index( 'id' )
            ->primary();
    }

    /**
     * Defines the data to be seeded.
     *
     * @param array $seeds
     * @return array
     */
    public function seed( array $seeds ): array {
        return [
            [
                'user_ref'   => 'ghjuyitjkuiy'
                'thingy_ref' => 1325546
            ],
            [
                'user_ref'   => 'eouroipewrjhiowe'
                'thingy_ref' => 897456
            ]
        ];
    }
}
```

> Example of table using [Perique App Config](https://perique.info/core/App/app_config) for table names.

```
class Use_Dependency_Migration extends Migration {
    protected $config;
    public function __construct( App_Config $config ) {
        $this->config = $config;
    }
    protected function table_name(): string {
        return $this->config->db_tables('from_app_config');
    }
}
```

### Create the Migrations service

[](#create-the-migrations-service)

The Perique Migrations Module requires the Plugin Life Cycle to be added to the Perique App. This is to ensure that the migrations are run at the correct time.

```
// @file plugin.php

// Boot the app as normal and create an instance of Plugin_State_Controller
$app = (new App_Factory())
    // setup the app as normal
    ->default_setup()

    // Ensure Plugin Life Cycle is added
    ->module(Perique_Plugin_Life_Cycle::class)

    // Add the Migrations module
    ->module(
        Perique_Migrations::class,
        function( Perique_Migrations $module ) {

            // Optional key
            $module->set_migration_log_key( 'acme_plugin_migrations' )

            // Add you migrations
            $module->add_migration(Acme_Migration::class)
            $module->add_migration(Some_Migration_With_Dependencies::class);
        }
    )
    ->boot();
```

Migration Model
---------------

[](#migration-model)

> All models must extend from the ( `abstract` ) `PinkCrab\Perique\Migration\Migration` class

```
class DI_Migration extends Migration {

    /** Services used */
    protected Some_Service $some_service;
    protected App_Config $config;

    /** These would be injected automatically via Perique DI */
    public function __construct(Some_Service $some_service, App_Config $config){
        $this->some_service = $some_service;
        $this->config = $config;
    }

    /** Gets the table name from the App_Config (Perique Config) */
    protected function table_name(): string {
        return $this->config->db_tables('from_app_config');
    }

    /**Defines the schema for the migration. */
    public function schema( Schema $schema_config ): void {
        $schema_config->column( 'id' )->unsigned_int( 11 )->auto_increment();
        $schema_config->index( 'id' )->primary();
        $schema_config->column( 'user_ref' )->text( 11 );
        $schema_config->column( 'thingy_ref' )->int( 11 );
    }

    /**
     * Defines the data to be seeded. */
    public function seed( array $seeds ): array {
        return $this->some_service->seed_data();
    }

    /** Is this table dropped on deactivation (Defaults to false). */
    public function drop_on_deactivation(): bool {
        return false;
    }

    /** Drop table on uninstall. (Defaults to false). */
    public function drop_on_uninstall(): bool {
        return true;
    }

    /** Should this migration be seeded on activation. (Defaults to true). */
    public function seed_on_inital_activation(): bool {
        return true;
    }
}
```

Methods
-------

[](#methods)

---

> ### \_\_construct(...$deps)
>
> [](#__constructdeps)
>
> @param mixed ...$deps Injected via the DI Container

You can inject any dependencies you need, so long as they either be inferred by the Type or has the rules define in the DI Rules. [See the di container docs for more details](https://perique.info/core/DI/)

---

> ### table\_name(): string
>
> [](#table_name-string)
>
> @return string
> @required method

This should return the final name for the table. This can be defined as a string literal or via an injected dependency (such as ['App\_Config'](https://perique.info/core/App/app_config))

```
/**
 * Returns the table name from the apps config.
 *
 * @return string
 */
protected function table_name(): string {
    return $this->config->db_tables('from_app_config');
}
```

---

> ### schema( Schema $schema\_config ): void
>
> [](#schema-schema-schema_config--void)
>
> @param PinkCrab\\Table\_Builder\\Schema $schema
> @return null @required method

This allows for the definition of the tables schema. Please see the [WPDB Migration](https://github.com/Pink-Crab/WP_DB_Migration) and [WPDB Table Builder](https://github.com/Pink-Crab/WPDB-Table-Builder) libraries for more details

```
/**
 * Defines the schema for the migration.
 *
 * @param Schema $schema
 * @return void
 */
public function schema( Schema $schema ): void{
    $schema->column('id')->unsigned_int(12)->auto_increment();
    // Define rest of schema
}
```

---

> ### seed( array $seeds ): array
>
> [](#seed-array-seeds--array)
>
> @param array&lt;int, array&lt;string, mixed&gt;&gt; $seeds
> @return array&lt;int, array&lt;string, mixed&gt;&gt;

Returns the data used to populate the table with. Should be returned as an array or arrays with matching column (key) and value pairs.

```
/**
 * Defines the schema for the migration.
 *
 * @param array $seeds
 * @return array
 */
public function seed( array $seeds ): array {
    return [
        ['columnA' => 'value1', 'columnB' => 1.11],
        ['columnA' => 'value2', 'columnB' => 2.22],
    ];
}
```

---

> ### drop\_on\_deactivation(): bool
>
> [](#drop_on_deactivation-bool)
>
> @return bool

Depending on the return value, the table can be dropped on deactivation. Defaults to `FALSE`

```
/**
 * Is this table dropped on deactivation (Defaults to false)
 * @return bool
 */
public function drop_on_deactivation(): bool {
    return true;
}
```

---

> ### drop\_on\_uninstall(): bool
>
> [](#drop_on_uninstall-bool)
>
> @return bool

Depending on the return value, the table can be dropped on uninstall. Defaults to `FALSE`

```
/**
 * Is this table dropped on uninstall (Defaults to false)
 * @return bool
 */
public function drop_on_uninstall(): bool {
    return true;
}
```

---

> ### seed\_on\_inital\_activation(): bool
>
> [](#seed_on_inital_activation-bool)
>
> @return bool

Depending on the return value, will populate tables with defined seeded data Defaults to `TRUE`

> Tables are only seeded once, even in the event of a later update.

```
/**
 * Should this migration be seeded on activation. (Defaults to true)
 * @return bool
 */
public function seed_on_inital_activation(): bool {
    return true;
}
```

Change Log
----------

[](#change-log)

- 2.1.0 - Update dependencies to support Perique V2.1
- 2.0.0 - Support for Perique V2.\*
- 1.0.0 - Initial Release (Supports Perique V1.2-1.4)
- 0.1.1 - Update dependencies and GH Action pipelines.
- 0.1.0 - Docs added, sample project created.
- 0.1.0-rc2 - Now uses [Perique Plugin Life Cycle 0.2](https://github.com/Pink-Crab/Perique_Plugin_Life_Cycle) and removes unneeded files when used as a lib via gitattributes
- 0.1.0-rc1 Inital BETA release.

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance92

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~305 days

Recently: every ~357 days

Total

6

Last Release

72d ago

Major Versions

0.1.0 → 1.0.02023-03-02

1.0.0 → 2.0.02023-04-03

PHP version history (4 changes)0.1.0-rc1PHP &gt;=7.1.0

1.0.0PHP &gt;=7.2.0

2.0.0PHP &gt;=7.4.0

2.1.0PHP &gt;=8.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d82b9e8ef7816d3d0b9812ad233f61f6a313f529e0ac85721781b46ad292e1ea?d=identicon)[glynnquelch](/maintainers/glynnquelch)

---

Top Contributors

[![gin0115](https://avatars.githubusercontent.com/u/28779094?v=4)](https://github.com/gin0115 "gin0115 (98 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pinkcrab-perique-migration/health.svg)

```
[![Health](https://phpackages.com/badges/pinkcrab-perique-migration/health.svg)](https://phpackages.com/packages/pinkcrab-perique-migration)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M190](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M255](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M591](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
