PHPackages                             mitsuki/mitsuki-db-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. [Framework](/categories/framework)
4. /
5. mitsuki/mitsuki-db-migrations

ActiveLibrary[Framework](/categories/framework)

mitsuki/mitsuki-db-migrations
=============================

A lightweight, fluent database migration wrapper for the Mitsuki framework, built on top of Phinx.

v1.2.0(1w ago)10MITPHPCI passing

Since Mar 9Pushed 1w agoCompare

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

READMEChangelogDependencies (5)Versions (5)Used By (0)

Mitsuki Database Migrations
===========================

[](#mitsuki-database-migrations)

**Mitsuki Database Migrations** is a lightweight, fluent schema builder for PHP. Built as a powerful wrapper around [Phinx](https://phinx.org/), it allows you to define your database structure using a clean, expressive syntax inspired by Laravel's Migration system.

✨ Features
----------

[](#-features)

- **Fluent API**: Define tables and columns using clean method chaining.
- **Smart Migrations**: Automatically detects if a table exists to choose between `CREATE` or `ALTER`.
- **Standardized Fields**: Quick helpers for primary keys (`id()`) and tracking (`timestamps()`).
- **Relationship Helpers**: Intelligent foreign key resolution with `foreignIdFor()`.
- **Phinx Powered**: Seamlessly integrates with your existing Phinx environments and commands.
- **Fully Tested**: High-reliability codebase tested with Pest PHP and Mockery.

---

🚀 Installation &amp; Setup
--------------------------

[](#-installation--setup)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require mitsuki/db-migrations
```

### 2. Initialize Phinx

[](#2-initialize-phinx)

Ensure your `phinx.php` is configured to use the Mitsuki template and environment variables.

---

🛠 Usage
-------

[](#-usage)

### 1. Basic Table Creation

[](#1-basic-table-creation)

Use the `Schema` facade. It coordinates with the Phinx migration instance to execute your definitions.

```
use Mitsuki\Database\Schema\Schema;
use Mitsuki\Database\Table;
use Mitsuki\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    public function up(): void
    {
        Schema::create('users', function (Table $table) {
            $table->string('username', 100);
            $table->string('email')->nullable();
            $table->timestamps(); // Adds 'created_at' and 'updated_at'
        }, $this);
    }

    public function down(): void
    {
        $this->table('users')->drop()->save();
    }
}
```

### 2. 🔗 Foreign Keys &amp; Relationships

[](#2--foreign-keys--relationships)

The `foreignIdFor()` method simplifies relationship management by automatically guessing column and table names.

```
$table->foreignIdFor(\App\Models\User::class)
      ->constrained()
      ->onDelete('cascade');
```

---

💻 Console Commands
------------------

[](#-console-commands)

Mitsuki leverages the Phinx CLI. Here are the essential commands for your workflow:

### Create a New Migration

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

Generate a new migration file using the Mitsuki stub:

```
vendor/bin/phinx create MyNewMigration
```

### Run Migrations

[](#run-migrations)

Execute all pending migrations:

```
# Running in default environment (Testing/SQLite)
vendor/bin/phinx migrate

# Force a specific environment (Development/MySQL)
vendor/bin/phinx migrate -e development
```

### Rollback

[](#rollback)

Undo the last migration:

```
vendor/bin/phinx rollback
```

### Check Status

[](#check-status)

See the list of migrated and pending files:

```
vendor/bin/phinx status
```

---

⚙️ Configuration (`phinx.php`)
------------------------------

[](#️-configuration-phinxphp)

Mitsuki handles environment switching automatically based on your `.env` file:

Env VarDefaultDescription`ENVIRONEMENT``testing`Switches between `testing` (SQLite) and `development` (MySQL).`DB_CONNECTION``mysql`The database driver to use in development.`DB_DATABASE``mitsuki_db`The name of your database or path to SQLite file.---

🧠 Smart Save Logic
------------------

[](#-smart-save-logic)

Mitsuki is designed to be safe. When you call `save()`, the library checks the database state:

1. **If the table doesn't exist**: It executes a `CREATE TABLE` statement (with `id => false` to let the Blueprint manage the primary key).
2. **If the table exists**: It automatically switches to `ALTER TABLE` to add your new columns without destroying existing data.

---

🧪 Testing
---------

[](#-testing)

We take stability seriously. The library is fully covered by **Pest PHP** unit tests.

```
composer test
```

---

📄 License
---------

[](#-license)

The Mitsuki Database Migrations library is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

\*\*Developed with ❤️ by [Zgeniuscoders\*\*](mailto:zgeniuscoders@gmail.com)

---

###  Health Score

37

—

LowBetter than 84% of packages

Maintenance98

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

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

Total

4

Last Release

12d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/59ea5d2ce29d5426a3d7feabbcc7b07772b03dd80e4cd13afd6f9ac5e0469998?d=identicon)[zgenius](/maintainers/zgenius)

---

Top Contributors

[![zgeniuscoders](https://avatars.githubusercontent.com/u/101071661?v=4)](https://github.com/zgeniuscoders "zgeniuscoders (36 commits)")

---

Tags

phpframeworkdatabasemigrationsmitsukifluent-apischema builderphinx-wrapper

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/mitsuki-mitsuki-db-migrations/health.svg)

```
[![Health](https://phpackages.com/badges/mitsuki-mitsuki-db-migrations/health.svg)](https://phpackages.com/packages/mitsuki-mitsuki-db-migrations)
```

###  Alternatives

[utopia-php/database

A simple library to manage application persistence using multiple database adapters

74313.8k4](/packages/utopia-php-database)

PHPackages © 2026

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