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

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

alirezasalehizadeh/quick-migration
==================================

A quick package for implement migrations in your PHP project.

v1.8.0(2y ago)01141MITPHPPHP ^8.1CI failing

Since Mar 2Pushed 2y ago1 watchersCompare

[ Source](https://github.com/alirezasalehizadeh/QuickMigration)[ Packagist](https://packagist.org/packages/alirezasalehizadeh/quick-migration)[ RSS](/packages/alirezasalehizadeh-quick-migration/feed)WikiDiscussions 1.8.x Synced today

READMEChangelog (10)Dependencies (1)Versions (23)Used By (1)

QuickMigration
==============

[](#quickmigration)

Run your migration quickly with Quick Migration!

Requirements
------------

[](#requirements)

PHP &gt;= 8.1

#### Available database:

[](#available-database)

- MySql
- PostgreSql

Getting Started
---------------

[](#getting-started)

#### Installation:

[](#installation)

via Composer:

```
composer require alirezasalehizadeh/quick-migration

```

#### Migration class template:

[](#migration-class-template)

Create a `xMigration` class like this that must extends from `\Alirezasalehizadeh\QuickMigration\Migration` class:

```
use Alirezasalehizadeh\QuickMigration\Migration;
use Alirezasalehizadeh\QuickMigration\Structure\Structure;
use Alirezasalehizadeh\QuickMigration\Structure\StructureBuilder;

class xMigration extends Migration
{

    protected $database = "database name";

    protected $translator = "set database translator name from available translators array (default MySql)";

    public function set(): array
    {
        return Structure::create('table_name', function (StructureBuilder $structure) {
            // Write your structure here...
        });
    }

}
```

#### Run migration:

[](#run-migration)

Next, create a object from `xMigration` class and run `migrate` method:

```
// index.php

$connection = PDO connection object;

(new xMigration($connection))->migrate();
```

```
php index.php

```

##### drop table:

[](#drop-table)

```
// index.php

$connection = PDO connection object;

(new xMigration($connection))->drop('table name');
// OR
(new xMigration($connection))->dropIfExists('table name');
```

```
php index.php

```

Usage
-----

[](#usage)

#### Structure methods:

[](#structure-methods)

```
$structure->id(string $name);
$structure->uuid(string $name, int $length);
$structure->ulid(string $name, int $length);
$structure->string(string $name, int $length);
$structure->number(string $name);
$structure->text(string $name);
$structure->timestamp(string $name);
$structure->timestamps();
$structure->json(string $name);
$structure->enum(string $name, array $enums);
$structure->array(string $name, array $values);
$structure->foreign(string $column)->reference(string $column)->on(string $table);
```

\*NOTE: See the [Structure Test](https://github.com/alirezasalehizadeh/QuickMigration/blob/1.7.x/test/Structure/StructureBuilderTest.php) file for examples

#### Column attributes:

[](#column-attributes)

```
$structure->number('test')
->primary()                 // Set this as primary key
->nullable()                // Set this nullable or not
->unique()                  // Set this unique
->default(1)                // Set default value
->autoIncrement()           // Set this auto increment
->index()                   // Index this column
->unsigned()                // Set unsigned attribute
->after('column')           // Set this column after specific column
->check('test >= 0')        // Check a expression
->comment('this is test column')  // Set a comment
```

#### Custom Column:

[](#custom-column)

Sometimes it happens that you need a specific type of column that is not available in `Type` enum and you have to create it manually. `QuickMigration` has provided you with a quick and easy way to create a specific type of column!

To create a column, it is enough to set the `method name` equal to the `column type` and write the `column name` in the `first argument`, like this:

```
// TINYTEXT type not defined in `Type` enum

$structure = new StructureBuilder('table name');

$structure->tinyText('foo');
// ...
```

#### Commands:

[](#commands)

```
migrate();
dropIfExists(string $table);
drop(string $table);
createIndex(string $name, string $table, array $columns);    // It is used to index several columns together
dropIndex(string $name, string $table);
alterTable();
dropCheck(string $table, string $name);
```

\*NOTE: See the [Command Test](https://github.com/alirezasalehizadeh/QuickMigration/blob/1.7.x/test/Command/CommandTranslator/CommandTranslatorTest.php) file for examples

#### Get SQL:

[](#get-sql)

You can get the sql`s by call the migration class object as string:

```
$obj = new xMigration($connection);
$obj->dropIfExists('bar');
$obj->migrate();
echo $obj;

/**
DROP TABLE IF EXISTS `foo`.`bar`
CREATE TABLE `foo`.`bar` (`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, ...)
**/
```

##### Get SQL as File:

[](#get-sql-as-file)

You can use `export` method, for get your sql`s in a file:

```
$obj = new xMigration($connection);
$obj->dropIfExists('bar');
$obj->migrate();
$obj->export(string $fileName);

// Create a file named fileName.sql
```

#### Custom Foreign Key:

[](#custom-foreign-key)

A quick way to create a foreignkey is this that the `name of the method` must to be`foreign + {foreignColumnName}`:

```
$structure = new StructureBuilder('table name');

$structure->foreign('bar_id')->reference('id')->on('bar');
// OR
$structure->foreignBarId()->reference('id')->on('bar');
// ...
```

### Modify Table:

[](#modify-table)

Now, for modify your tables can use `change` method on `Structure`:

```
use Alirezasalehizadeh\QuickMigration\Migration;
use Alirezasalehizadeh\QuickMigration\Structure\Structure;
use Alirezasalehizadeh\QuickMigration\Structure\TableAlter;

class xMigration extends Migration
{

    protected $database = "database name";

    protected $translator = "set database translator name from available translators array (default MySql)";

    public function set(): array
    {
        return Structure::change('table_name', function (TableAlter $alter) {
            // Write your commands for modify table...
        });
    }

}
```

#### Run commands:

[](#run-commands)

```
// index.php

$connection = PDO connection object;

(new xMigration($connection))->alterTable();
```

```
php index.php

```

\*NOTE: See the [Table Alter Test](https://github.com/alirezasalehizadeh/QuickMigration/blob/1.7.x/test/Structure/StructureAlterTest.php) file for examples

Contributing
------------

[](#contributing)

Send pull request or open issue for contributing.

License
-------

[](#license)

[MIT](LICENSE).

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

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 ~11 days

Total

21

Last Release

986d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d2fea36dd7d7e08bb16f8800f37b9b56e69e0e5cc2749603c96efe6fb378cb1?d=identicon)[alirezasalehizadeh](/maintainers/alirezasalehizadeh)

---

Top Contributors

[![alirezasalehizadeh](https://avatars.githubusercontent.com/u/66994089?v=4)](https://github.com/alirezasalehizadeh "alirezasalehizadeh (74 commits)")

---

Tags

migrationphpphp-migration

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alirezasalehizadeh-quick-migration/health.svg)

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M117](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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