PHPackages                             maniaba/ci4-migration-safety-rector - 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. maniaba/ci4-migration-safety-rector

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

maniaba/ci4-migration-safety-rector
===================================

Rector rule for CodeIgniter 4 migrations: replaces silent $this-&gt;db-&gt;query() with queryOrFail() to surface DDL failures on production deployments.

02.5k↓40.1%PHPCI passing

Since Apr 29Pushed 1mo agoCompare

[ Source](https://github.com/maniaba/ci4-migration-safety-rector)[ Packagist](https://packagist.org/packages/maniaba/ci4-migration-safety-rector)[ RSS](/packages/maniaba-ci4-migration-safety-rector/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Custom [Rector](https://getrector.com/) rules for a CodeIgniter 4 application.

Rules
-----

[](#rules)

### `MigrationQueryToQueryOrFailRector`

[](#migrationquerytoqueryorfailrector)

Replaces fire-and-forget `$this->db->query($sql)` calls inside CI4 migration files with `$this->queryOrFail('ClassName', $sql)`.

**Why?**

On production CI4 deployments `DBDebug = false`, which means `$this->db->query()`silently returns `false` on SQL error instead of throwing an exception. The CI4 migration runner marks a migration as successful whenever `up()` returns without throwing — so a failed `CREATE TRIGGER` (or any DDL) is silently recorded as "run" while the trigger was never actually created in the database.

`MigrationHelper::queryOrFail()` wraps the call and throws a `RuntimeException`on failure, making migration failures visible in deployment logs.

**What is replaced:**

```
// Before — silently ignored on prod if the SQL fails
$this->db->query('CREATE TRIGGER `trg` AFTER INSERT ON `foo` FOR EACH ROW BEGIN END');
$this->db->query('DROP TRIGGER IF EXISTS `trg`');

// After
$this->queryOrFail('MyMigration', 'CREATE TRIGGER `trg` AFTER INSERT ON `foo` FOR EACH ROW BEGIN END');
$this->queryOrFail('MyMigration', 'DROP TRIGGER IF EXISTS `trg`');
```

**What is NOT replaced:**

```
// Assigned calls (SELECT queries) — the result is needed, left untouched
$result = $this->db->query('SELECT COUNT(*) FROM `orders`');

// Calls outside Database/Migrations/ path — rule doesn't activate
// Calls on other objects ($this->forge->query) — only $this->db->query is targeted
```

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

[](#installation)

```
composer require --dev maniaba/ci4-migration-safety-rector
```

Usage
-----

[](#usage)

In your project's `rector.php`:

```
use Maniaba\Rector\RectorRules\MigrationQueryToQueryOrFailRector;use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withRules([
        MigrationQueryToQueryOrFailRector::class,
    ]);
```

Local development (path repository)
-----------------------------------

[](#local-development-path-repository)

While developing locally alongside the main project, add to the main project's `composer.json`:

```
{
    "repositories": [
        {
            "type": "path",
            "url": "./ci4-migration-safety-rector"
        }
    ],
    "require-dev": {
        "maniaba/ci4-migration-safety-rector": "*"
    }
}
```

Then run `composer update maniaba/ci4-migration-safety-rector`.

Running tests
-------------

[](#running-tests)

```
composer test
```

> Tests use `XDEBUG_MODE=off` (set in `phpunit.xml.dist`) to prevent a Windows segfault caused by Xdebug coverage mode conflicting with Rector's heavy AST/reflection processing.

Coding style
------------

[](#coding-style)

```
composer cs       # check
composer cs-fix   # fix
```

Uses [CodeIgniter Coding Standard](https://github.com/CodeIgniter/coding-standard).

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance60

Regular maintenance activity

Popularity23

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

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.

### Community

Maintainers

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

---

Top Contributors

[![maniaba](https://avatars.githubusercontent.com/u/61078470?v=4)](https://github.com/maniaba "maniaba (6 commits)")

### Embed Badge

![Health badge](/badges/maniaba-ci4-migration-safety-rector/health.svg)

```
[![Health](https://phpackages.com/badges/maniaba-ci4-migration-safety-rector/health.svg)](https://phpackages.com/packages/maniaba-ci4-migration-safety-rector)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

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

8361.6M87](/packages/propel-propel1)[mpociot/laravel-composite-key

Support composite keys in your laravel app.

3544.8k1](/packages/mpociot-laravel-composite-key)

PHPackages © 2026

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