PHPackages                             codenom/schemas - 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. codenom/schemas

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

codenom/schemas
===============

Database schema management, for CodeIgniter 4

1.0(5y ago)214MITPHPPHP &gt;=7.2

Since Jul 25Pushed 5y ago1 watchersCompare

[ Source](https://github.com/codenomdev/codeigniter4-schemas)[ Packagist](https://packagist.org/packages/codenom/schemas)[ Docs](https://github.com/codenom/codeigniter4-schemas)[ RSS](/packages/codenom-schemas/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

codeigniter4-schemas
====================

[](#codeigniter4-schemas)

Database schema management, for CodeIgniter 4

Quick Start
-----------

[](#quick-start)

1. Install with Composer: `> composer require codenom/schemas`
2. Generate a new schema: `> php spark schemas`

Features
--------

[](#features)

- View your entire database mapped out in a cascading structure
- Read or detect table relationships for easy object-relation mapping (see e.g. [Tatter\\Relations](https://github.com/tattersoftware/codeigniter4-relations))
- Get helpful advice on optimizations to your database structure with schema analysis1
- Backup, restore, or deploy an entire database structure between servers or environments1
- Generate CodeIgniter 4 migration files from an existing database1
- Transfer projects to CodeIgniter 4 by reading schema files from other supported formats1

1 Some features are still in development. See **Handlers &gt; Development** for planned future expansion.

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

[](#installation)

Install easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities and always be up-to-date:

- `> composer require codenom/schemas`

Or, install manually by downloading the source files and adding the directory to `app/Config/Autoload.php`.

Configuration (optional)
------------------------

[](#configuration-optional)

The library's default behavior can be altered by extending its config file. Copy **bin/Schemas.php** to **app/Config/** and follow the instructions in the comments. If no config file is found in **app/Config** the library will use its own.

Usage
-----

[](#usage)

**Schemas** has four main functions, each with a variety of handlers available:

- *Draft*: Generates a new schema from a variety of sources
- *Archive*: Stores a copy of a schema for later use
- *Read*: Loads a schema for live access
- *Publish*: (not yet available) Modifies environments to match schema specs

The **Schemas** service is also available to simplify a workflow with convenient wrapper functions. At its most basic (with automation enabled), the service will draft, archive, and return a schema with one simple command:

```
$schema = service('schemas')->get();

```

You may want to control when portions of the workflow take place to optimize performance. Here is an example of one common process, mapping the default database group and storing the resulting schema to the cache:

```
// Map the database and store the schema in cache
$schemas = service('schemas');
$schemas->draft('database')->archive('cache');

// Load the schema from cache, add Model data, and get the updated schema
$schema = $schemas->read('cache')->draft('model')->get();

```

If you need to deviate from default handler configurations you can inject the handlers yourself:

```
$db = db_connect('alternate_database');
$databaseHandler = new \Codenom\Schemas\Drafter\Handlers\DatabaseHandler(null, $db);
$schema = $schemas->draft($databaseHandler)->get();

```

Command
-------

[](#command)

**Schemas** comes with a `spark` command for convenient schema generation and display:

```
`schemas [-draft handler1,handler2,...] [-archive handler1,... | -print]`

```

Use the command to test and troubleshoot, or add it to your cron for periodic schema caching:

```
php spark schemas -draft database,model -archive cache

```

Automation
----------

[](#automation)

By default automation is turned on, but this can be configured via the `$automate` toggles in your config file. Automation will allow the service to fall back on a Reader, or even on a Drafter should it fail to have a schema already loaded. While automation makes using the library very easy, it can come at a performance cost if your application is not configured correctly, since it may draft a schema on every page load. Use automation to help but don't let it become a crutch.

Structure
---------

[](#structure)

**Schemas** uses foreign keys, indexes, and naming convention to detect relationships automatically. Make sure your database is setup using the appropriate keys and foreign keys to assist with the detection. Naming conventions follow the format of `{table}_id` for foreign keys and `{table1}_{table2}` for pivot tables. For more examples on relationship naming conventions consult the Rails Guide [Active Record Associations](https://guides.rubyonrails.org/association_basics.html#the-types-of-associations)(and please excuse the Ruby reference).

### Intervention

[](#intervention)

Should autodetection fail or should you need to deviate from conventions there are a few tools you can use to overwrite or augment the generated schema.

- **Config/Schemas**: the Config file includes a variable for `$ignoredTables` that will let you skip tables entirely. By default this includes the framework's `migrations` table.
- **app/Schemas/{file}.php**: The `DirectoryHandler` will load any schemas detected in your **Schemas** directory - this gives you a chance to specify anything you want. See [tests/\_support/Schemas/Good/Products.php](tests/_support/Schemas/Good/Products.php) for an example.

Drafting
--------

[](#drafting)

Currently supported handlers:

- Database
- Model
- PHP
- Directory (PHP import only)

Archiving/reading
-----------------

[](#archivingreading)

- Cache

Database Support
----------------

[](#database-support)

All CodeIgniter 4 database drivers work but due to some differences in index handling they may not all report the same results. Example: see skipped tests for SQLite3.

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

[](#development)

The eventual goal is to support mapping from and deploying to any source. Planned handler implementations include:

- `Publisher\DatabaseHandler`: Recreate a live database from its schema
- `MigrationsHandler`: Create a schema from migration files, or vice versa
- `FileHandler`: A wrapper for importing and exporting from popular schema file formats
- Lots more...

And the file-specific handlers:

- `PhpHandler->archive()`: Create a PHP file with a Schema object in `$schema`
- `XmlHandler`: Support for Doctrine-style XML files
- More to come...

Want to help out? All code and issues are managed on GitHub at [Codenom\\Schemas](https://github.com/codenomdev/codeigniter4-schemas)

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

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

2123d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

databasecodeignitermappingstructurecodeigniter4schemas

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codenom-schemas/health.svg)

```
[![Health](https://phpackages.com/badges/codenom-schemas/health.svg)](https://phpackages.com/packages/codenom-schemas)
```

###  Alternatives

[tatter/schemas

Database schema management, for CodeIgniter 4

2328.5k1](/packages/tatter-schemas)[propel/propel1

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

8481.6M87](/packages/propel-propel1)[tatter/relations

Entity relationships for CodeIgniter 4

9022.3k1](/packages/tatter-relations)[concretecms/doctrine-xml

Define database structure via XML using Doctrine data types

11100.8k2](/packages/concretecms-doctrine-xml)[proesio/pipe

PIPE - ORM en Español.

139.2k1](/packages/proesio-pipe)

PHPackages © 2026

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