PHPackages                             j-angnoe/simpleschema - 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. j-angnoe/simpleschema

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

j-angnoe/simpleschema
=====================

Sync mysql database schemas with file based schemas.

019PHP

Since Dec 31Pushed 4y ago1 watchersCompare

[ Source](https://github.com/j-angnoe/simpleschema)[ Packagist](https://packagist.org/packages/j-angnoe/simpleschema)[ RSS](/packages/j-angnoe-simpleschema/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

SimpleSchema
============

[](#simpleschema)

SimpleSchema is a MySQL utility that syncs your database-schema with a schema defined in file(s).

When designing models, or while prototyping, you may need to perform a lot of schema changes. You might be familiar with database migration solutions offered by popular frameworks, while this method offers high accuracy and reproducability, it become tidious when you don't get the migration step right the first time.

A nicer approach would be if you could just write your schema down in a file and let a tool make the necessary database schema modifications for you.

This is what simpleschema is all about.

A sample database definition:

```
topics:
        `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT
        `name` varchar(40) DEFAULT NULL

users:
        `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT
        `name` varchar(40) DEFAULT NULL

posts:
        `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT
        `name` varchar(255) DEFAULT NULL
        `content` text DEFAULT NULL
        `topic_id` int(11) DEFAULT NULL
        KEY `fk_topic_id_topics_id` (`topic_id`)
        CONSTRAINT `fk_topic_id_topics_id` FOREIGN KEY (`topic_id`) REFERENCES `topics` (`id`)
```

The format closely follows SQL format but with some annoyances stripped: comma's and CREATE TABLE stuff.

Save this to myschema.simpleschema.txt

Now compare the schema to your database:

`simpleschema diff`

Which tells you:

```
- ALTER TABLE `users` ADD COLUMN `password` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL AFTER `name`
- ALTER TABLE `posts` MODIFY COLUMN `name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL AFTER `id`
```

And if your content with these changes, run them:

`simpleschema run`

Warning: SimpleSchema can DROP COLUMNS, KEYS, etc. Review the changes CAREFULLY before applying to prevent UNINTENTED DATA LOSS.

Making it work
==============

[](#making-it-work)

simpleschema checks the following ENVIRONMENT variables: DB\_HOST DB\_PORT DB\_USERNAME DB\_PASSWORD DB\_DATABASE

You can supply these settings as prefixing them to your command:

`DB_HOST=x DB_PORT=3306 DB_USERNAME=user DB_PASSWORD=pass DB_DATABASE=mydb simpleschema run`

Ways to set environment variables:

Or, as a last option, you can add a `simpleschema` to any package.json under the current directory. This method is suitable for development purposes.

```
"simpleschema" : {
    "DB_HOST" : "....",
    "DB_PORT" : "...",
    "DB_USERNAME" : "...",
    "DB_PASSWORD" : "...",
    "DB_DATABASE" : "..."
}
```

Convert an existing schema to simpleschema format
=================================================

[](#convert-an-existing-schema-to-simpleschema-format)

Use `simpleschema export` to get going. Write it to a file by forwarding the output to a file. `simpleschema export &gt; myschema.simpleschema.txt

Simpleschema files
==================

[](#simpleschema-files)

the simpleschema binary will `find` files that end contain '.simpleschema.' in there name and concatenate all there content. This allows you to store your break up a giant schema into logical parts and distribute these files inside your codebase.

Use `simpleschema ls` to list all the simpleschema files in a project. Use `simpleschema cat` to view the combined output of all the files.

Note on FULLTEXT
================

[](#note-on-fulltext)

if you use fulltext columns, we cannot use temporary tables for comparison. It will create a full table postfixed with the term `_simpleschema_tmp`. This still needs to be cleaned up at some point.

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity27

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://www.gravatar.com/avatar/a5c43eab887b4a97df5d72331ab607920bf1c4cbcb9883aa1f5b888bee287813?d=identicon)[j-angnoe](/maintainers/j-angnoe)

---

Top Contributors

[![j-angnoe](https://avatars.githubusercontent.com/u/4835885?v=4)](https://github.com/j-angnoe "j-angnoe (13 commits)")

### Embed Badge

![Health badge](/badges/j-angnoe-simpleschema/health.svg)

```
[![Health](https://phpackages.com/badges/j-angnoe-simpleschema/health.svg)](https://phpackages.com/packages/j-angnoe-simpleschema)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M545](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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