PHPackages                             sabarinathan/ci4-schema-to-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. sabarinathan/ci4-schema-to-migration

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

sabarinathan/ci4-schema-to-migration
====================================

Generate CodeIgniter 4 migration files from an existing database schema.

00PHP

Since Jan 15Pushed 5mo agoCompare

[ Source](https://github.com/sabarinathancs/ci4-schema-to-migration)[ Packagist](https://packagist.org/packages/sabarinathan/ci4-schema-to-migration)[ RSS](/packages/sabarinathan-ci4-schema-to-migration/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

CI4 Schema to Migration
=======================

[](#ci4-schema-to-migration)

A CodeIgniter 4 package that generates migration files from your existing database tables.

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

[](#installation)

### Option 1: Via Composer (Recommended)

[](#option-1-via-composer-recommended)

Run the following command in your CodeIgniter 4 project root:

```
composer require sabarinathan/ci4-schema-to-migration
```

### Option 2: Manual Installation (Local Repositories)

[](#option-2-manual-installation-local-repositories)

If the package is not available on Packagist yet, you can refer to it locally.

1. Open your CI4 project's `composer.json`.
2. Add a `repositories` section: ```
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/sabarinathan/ci4-schema-to-migration"
        }
    ],
    ```
3. Run: ```
    composer require sabarinathan/ci4-schema-to-migration:dev-main
    ```

### Command Discovery

[](#command-discovery)

After installation, the command `dbmigration:generate` will be automatically discovered by CodeIgniter 4's `Spark` CLI through the `composer` autoloading. You don't need to manually register it.

Verify it is listed by running:

```
php spark list
```

You should see `dbmigration:generate` under the `Database` group.

Usage
-----

[](#usage)

Run the Spark command to generate a migration for a specific table:

```
php spark dbmigration:generate
```

Or generate migrations for **ALL** tables in the database:

```
php spark dbmigration:generate --all
```

Example:

```
php spark dbmigration:generate users
```

This will create a new migration file in `app/Database/Migrations/`.

Features
--------

[](#features)

- **Inspects Database**: Reads column definitions, types, defaults, and nullability.
- **Keys Support**: Detects Primary Keys, Foreign Keys, and other Indexes.
- **CI4 Compatibility**: Generates standard `CodeIgniter\Database\Migration` classes using `Forge`.
- **Safe**: Uses `createTable(..., true)` to prevent errors if the table already exists (IF NOT EXISTS).

Structure
---------

[](#structure)

- `src/Commands/GenerateMigration.php`: The Spark command.
- `src/Libraries/DatabaseInspector.php`: Abstraction for reading DB schema.
- `src/Libraries/MigrationGenerator.php`: Logic to build migration code.
- `src/Templates/migration.tpl.php`: Template for the migration file.

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance48

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 80% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5072200?v=4)[Sabarinathan Kalidass](/maintainers/sabarinathancs)[@sabarinathancs](https://github.com/sabarinathancs)

---

Top Contributors

[![sabarinathancs](https://avatars.githubusercontent.com/u/5072200?v=4)](https://github.com/sabarinathancs "sabarinathancs (4 commits)")[![sabarinathancs-creator](https://avatars.githubusercontent.com/u/247946049?v=4)](https://github.com/sabarinathancs-creator "sabarinathancs-creator (1 commits)")

### Embed Badge

![Health badge](/badges/sabarinathan-ci4-schema-to-migration/health.svg)

```
[![Health](https://phpackages.com/badges/sabarinathan-ci4-schema-to-migration/health.svg)](https://phpackages.com/packages/sabarinathan-ci4-schema-to-migration)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/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)
