PHPackages                             adhuham/pretty-phinx - 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. adhuham/pretty-phinx

ActiveLibrary[Database &amp; ORM](/categories/database)

adhuham/pretty-phinx
====================

Phinx, but prettified

v1.0.0(4y ago)124MITPHPPHP &gt;=7.2

Since Jul 10Pushed 4y ago1 watchersCompare

[ Source](https://github.com/adhuham/pretty-phinx)[ Packagist](https://packagist.org/packages/adhuham/pretty-phinx)[ Docs](https://adhuham.com/)[ RSS](/packages/adhuham-pretty-phinx/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Pretty Phinx
============

[](#pretty-phinx)

Pretty Phinx adds prettified and readable syntax to popular **[Phinx](https://github.com/cakephp/phinx)** migration library. Phinx's default syntax can become cluttered and hard-to-read at times. Pretty Phinx uses method-chaining and adds readable methods for popular column types.

Installation
------------

[](#installation)

Using composer

```
composer require adhuham/pretty-phinx

```

### Console

[](#console)

Use `vendor/bin/pretty-phinx` instead of `vendor/bin/phinx` to access console tools.

### Migrations

[](#migrations)

You need to extend `PrettyPhinx\Migration\AbstractMigration` instead of `Phinx\Migration\AbstractMigration` base in your migration classes. When you generate migration classes using `vendor/bin/pretty-phinx` it will create the classes with `vendor/bin/pretty-phinx`.

```
use PrettyPhinx\Migration\AbstractMigration;

class MyNewMigration extends AbstractMigration
{
    public function change()
    {
    }
}
```

#### Creating tables

[](#creating-tables)

```
$post = $this->table('post');
$post->bigIncrements('id')->add();
$post->string('slug')->unique()->add();
$post->string('title')->length(255)->add();
$post->text('content')->nullable()->add();
$post->create();
```

#### Updating tables

[](#updating-tables)

```
$post = $this->table('post');
$post->bigIncrements('id')->change();
$post->string('slug')->unique()->change();
$post->string('title')->length(255)->nullable()->change();
$post->text('content')->nullable()->change();

$post->string('sub_title')->after('title');
$post->update();
```

Use `->change()` instead of `->add()` to amend column.

#### Primary Keys

[](#primary-keys)

By default, automatic primary key creation is disabled. You've to manually create the primary keys using [auto-incrementing methods](#auto-incrementing-methods).

#### Foreign Keys

[](#foreign-keys)

```
$tag = $this->table('tag');
$tag->bigIncrements()->add();
$tag->string('slug')->unique()->add();
$tag->string('name')->add();
$tag->create();

$post = $this->table('post');
$post->unsignedBigInteger('tag_id');

$post->foreign('tag_id')->references('id')->on('tag')
  ->onUpdate('cascade')
  ->onDelete('cascade')
  ->add();

$post->update();
```

Use Phinx's default syntax to delete or existence-check foreign keys (`$table->dropForeignKey('tag_id')` and `$table->hasForeignKey('tag_id')`). See [Phinx Docs: Working With Foreign Keys](https://book.cakephp.org/phinx/0/en/migrations.html#working-with-foreign-keys)

### Methods

[](#methods)

```
$table->unsignedBigInteger();
$table->unsignedMediumInteger();
$table->unsignedSmallInteger();
$table->unsignedTinyInteger();
$table->unsignedInteger();

$table->bigInteger();
$table->mediumInteger();
$table->smallInteger();
$table->tinyInteger();
$table->integer();

$table->text();
$table->longText();
$table->mediumText();
$table->tinyText();

$table->decimal($precision = 8, $scale = 2);
$table->boolean();

$table->dateTime();
$table->date();
$table->time();
```

#### Auto-incrementing

[](#auto-incrementing)

```
// these methods will create an auto-incrementing column
$table->bigIncrements();
$table->mediumIncrements();
$table->smallIncrements();
$table->tinyIncrements();
$table->increments();
```

#### Modifiers

[](#modifiers)

```
// ->length()
$table->string('title')->length(100)->add();

// ->default()
$table->string('title')->default('untitled')->add();

// ->nullable()
$table->string('title')->nullable()->add();
$table->string('title')->nullable(false)->add(); // disable null (NOT NULL)

// ->unique()
$table->string('title')->unique()->add();

// ->index()
$table->string('title')->index()->add();

// ->after()
$table->string('title')->after('another_column')->add();

// ->charset()
$table->string('title')->charset('utf8')->add();

// ->collation()
$table->string('title')->collation('utf8_general_ci')->add();
```

#### Encoding

[](#encoding)

Default charset/collation is `utf8mb4` and `utf8mb4_unicode_ci` for both table and columns.

To change the collation of a table

```
$table = $this->table('post');
// this changes the collation of "post" table
$table->collation('utf8_general_ci');
// ...
// ...
$table->update();
```

License
-------

[](#license)

MIT License

Copyright (c) 2021 Mohamed Adhuham

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

1771d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/32795085?v=4)[adhham](/maintainers/adhuham)[@adhuham](https://github.com/adhuham)

---

Tags

phpmysqlmigrationsdatabase migrationsphinxpretty-phinx

### Embed Badge

![Health badge](/badges/adhuham-pretty-phinx/health.svg)

```
[![Health](https://phpackages.com/badges/adhuham-pretty-phinx/health.svg)](https://phpackages.com/packages/adhuham-pretty-phinx)
```

###  Alternatives

[robmorgan/phinx

Phinx makes it ridiculously easy to manage the database migrations for your PHP app.

4.5k46.2M405](/packages/robmorgan-phinx)[odan/phinx-migrations-generator

Migration generator for Phinx

235847.8k23](/packages/odan-phinx-migrations-generator)[masom/lhm

Large Hadron Migrator for phinx

309.3k](/packages/masom-lhm)[popphp/pop-db

Pop Db Component for Pop PHP Framework

1814.6k11](/packages/popphp-pop-db)

PHPackages © 2026

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