PHPackages                             rasuvaeff/yii3-audit-log-db - 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. rasuvaeff/yii3-audit-log-db

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

rasuvaeff/yii3-audit-log-db
===========================

Database-backed audit writer for rasuvaeff/yii3-audit-log

v1.0.0(today)00BSD-3-ClausePHPPHP 8.3 - 8.5CI passing

Since Jun 20Pushed todayCompare

[ Source](https://github.com/rasuvaeff/yii3-audit-log-db)[ Packagist](https://packagist.org/packages/rasuvaeff/yii3-audit-log-db)[ Docs](https://github.com/rasuvaeff/yii3-audit-log-db)[ RSS](/packages/rasuvaeff-yii3-audit-log-db/feed)WikiDiscussions master Synced today

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

rasuvaeff/yii3-audit-log-db
===========================

[](#rasuvaeffyii3-audit-log-db)

[![Stable Version](https://camo.githubusercontent.com/52cad7efd2a678e22d67dc38d1db39f29e76752c8632a1c54ce77e64cbb6bd53/68747470733a2f2f706f7365722e707567782e6f72672f7261737576616566662f796969332d61756469742d6c6f672d64622f762f737461626c65)](https://packagist.org/packages/rasuvaeff/yii3-audit-log-db)[![Total Downloads](https://camo.githubusercontent.com/c9d320eaf1fa2d0eca123789fa5f4b2444062f70143b8495adbdd3e3e857414f/68747470733a2f2f706f7365722e707567782e6f72672f7261737576616566662f796969332d61756469742d6c6f672d64622f646f776e6c6f616473)](https://packagist.org/packages/rasuvaeff/yii3-audit-log-db)[![Build](https://github.com/rasuvaeff/yii3-audit-log-db/actions/workflows/build.yml/badge.svg)](https://github.com/rasuvaeff/yii3-audit-log-db/actions)[![Static analysis](https://github.com/rasuvaeff/yii3-audit-log-db/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/rasuvaeff/yii3-audit-log-db/actions)[![Psalm Level](https://camo.githubusercontent.com/ab3af0e0177c8b69e7dca0c44dbbde3ed59c6c5392fac454cdcc760fc0f743a8/68747470733a2f2f73686570686572642e6465762f6769746875622f7261737576616566662f796969332d61756469742d6c6f672d64622f6c6576656c2e737667)](https://shepherd.dev/github/rasuvaeff/yii3-audit-log-db)[![PHP](https://camo.githubusercontent.com/dc16c19e1742948be019faea0c0f6e2e5567441c0623af198442eaacf046005a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f7261737576616566662f796969332d61756469742d6c6f672d64622f706870)](https://packagist.org/packages/rasuvaeff/yii3-audit-log-db)[![License](https://camo.githubusercontent.com/64fe1a752f02e025e743dce34f3f31e6d1c369a84b9a7647378d74c18cab3ed6/68747470733a2f2f706f7365722e707567782e6f72672f7261737576616566662f796969332d61756469742d6c6f672d64622f6c6963656e7365)](https://packagist.org/packages/rasuvaeff/yii3-audit-log-db)

Database-backed `AuditWriter` for [`rasuvaeff/yii3-audit-log`](https://github.com/rasuvaeff/yii3-audit-log). Persists audit events to any `yiisoft/db`-compatible database (SQLite, MySQL, PostgreSQL, etc.).

> Using an AI coding assistant? [llms.txt](llms.txt) has a compact API reference you can use.

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

[](#requirements)

- PHP 8.3+
- `rasuvaeff/yii3-audit-log` ^1.0
- `yiisoft/db` ^2.0

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

[](#installation)

```
composer require rasuvaeff/yii3-audit-log rasuvaeff/yii3-audit-log-db
```

Migration
---------

[](#migration)

Run the bundled migration to create the `audit_log` table:

```
// Register the migration in your migration runner:
// migrations/M260620000000CreateAuditLogTable.php
// from vendor/rasuvaeff/yii3-audit-log-db/migrations/
```

The migration creates:

ColumnTypeNotes`id`VARCHAR(32) PK32-char hex from `AuditLogger``actor_type`VARCHAR(32)`user` / `system``actor_id`VARCHAR(255) NULLnull for system actor`actor_name`VARCHAR(255) NULLdisplay name, optional`action`VARCHAR(64)`create` / `update` / `delete` / custom`subject_type`VARCHAR(255)entity type, e.g. `order``subject_id`VARCHAR(255)entity id`changes`TEXTJSON array of `{field, old, new}` objects`occurred_at`VARCHAR(30)`Y-m-d H:i:s` UTC`request_id`VARCHAR(255) NULLfrom `AuditMetadata``ip`VARCHAR(45) NULLfrom `AuditMetadata``user_agent`TEXT NULLfrom `AuditMetadata`Indexes: `(subject_type, subject_id, occurred_at)`, `(actor_type, actor_id, occurred_at)`, `(occurred_at)`.

Yii3 config-plugin
------------------

[](#yii3-config-plugin)

Install `rasuvaeff/yii3-audit-log` (core) and `rasuvaeff/yii3-audit-log-db` (adapter). The adapter's `config/di.php` automatically binds `AuditWriter` to `DbAuditWriter`.

The core's `config/di.php` wires `AuditLogger`. You only need to bind `ClockInterface`in your application config:

```
// config/common/di/clock.php
use Psr\Clock\ClockInterface;

return [
    ClockInterface::class => MySystemClock::class,
];
```

Custom table name via params:

```
// config/common/params.php
return [
    'rasuvaeff/yii3-audit-log-db' => [
        'table' => 'my_audit_log',
    ],
];
```

Usage
-----

[](#usage)

### Write via AuditLogger

[](#write-via-auditlogger)

```
use Rasuvaeff\Yii3AuditLog\AuditActor;
use Rasuvaeff\Yii3AuditLog\AuditChangeSet;
use Rasuvaeff\Yii3AuditLog\AuditLogger;
use Rasuvaeff\Yii3AuditLog\AuditSubject;

// Injected via DI:
/** @var AuditLogger $logger */

$logger->logChange(
    actor: AuditActor::user(id: (string) $user->id, name: $user->name),
    subject: AuditSubject::of(type: 'order', id: (string) $order->id),
    changes: AuditChangeSet::fromArrays(old: $before, new: $after),
);
```

### Use directly

[](#use-directly)

```
use Rasuvaeff\Yii3AuditLogDb\DbAuditWriter;

$writer = new DbAuditWriter(db: $db, table: 'audit_log');
$writer->write(event: $auditEvent);
```

Security
--------

[](#security)

- `DbAuditWriter` validates the table name against `/^[A-Za-z_]\w*(\.[A-Za-z_]\w*)?$/` — schema-qualified names like `public.audit_log` are allowed; arbitrary strings are rejected.
- All event field values are passed as bound parameters via `yiisoft/db` — no SQL injection risk.
- `changes` values are whatever `AuditChangeSet` contains. Apply `SensitiveValueMasker` in `AuditLogger` before this writer runs (default in core DI).

Examples
--------

[](#examples)

See [`examples/`](examples/) for runnable scripts.

Development
-----------

[](#development)

```
# from monorepo root (/home/rasuvaeff/projects/rasuvaeff)
make -C yii3-audit-log-db install
make -C yii3-audit-log-db build
make -C yii3-audit-log-db cs-fix
make -C yii3-audit-log-db test
```

Or with Docker directly:

```
docker run --rm -v "$PWD":/repo -w /repo/yii3-audit-log-db composer:2 composer build
```

License
-------

[](#license)

BSD-3-Clause. See [LICENSE.md](LICENSE.md).

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b0812d5572a7041dfe36e222d295b2e6dc55833a605350fcde58a51a5965ed30?d=identicon)[rasuvaeff](/maintainers/rasuvaeff)

---

Top Contributors

[![rasuvaeff](https://avatars.githubusercontent.com/u/1352718?v=4)](https://github.com/rasuvaeff "rasuvaeff (2 commits)")

---

Tags

databasedbAudityii3audit-log

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rasuvaeff-yii3-audit-log-db/health.svg)

```
[![Health](https://phpackages.com/badges/rasuvaeff-yii3-audit-log-db/health.svg)](https://phpackages.com/packages/rasuvaeff-yii3-audit-log-db)
```

###  Alternatives

[robmorgan/phinx

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

4.5k47.9M442](/packages/robmorgan-phinx)[spatie/laravel-translation-loader

Store your language lines in the database, yaml or other sources

8453.1M60](/packages/spatie-laravel-translation-loader)[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4603.0M](/packages/damienharper-auditor-bundle)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4563.1M37](/packages/aura-sqlquery)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

6421.0M1](/packages/sonata-project-entity-audit-bundle)[damienharper/auditor

The missing audit log library.

1933.0M9](/packages/damienharper-auditor)

PHPackages © 2026

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