PHPackages                             dlevsha/compalex - 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. dlevsha/compalex

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

dlevsha/compalex
================

Compalex is a lightweight script to compare two database schemas. It supports MySQL, MS SQL Server and PostgreSQL

0.4.0(10y ago)44245122[3 PRs](https://github.com/dlevsha/compalex/pulls)MITPHPPHP &gt;=5.4.0

Since Dec 17Pushed 4y ago18 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

README
======

[](#readme)

What is Compalex?
-----------------

[](#what-is-compalex)

Compalex is a lightweight script to compare two database schemas. It supports MySQL, MS SQL Server and PostgreSQL.

Try [demo](http://demo.compalex.net/) or visit

How to use
----------

[](#how-to-use)

The easiest way to use Compalex is to use Docker.

You can build your own container using Dockerfile or use Docker Hub image:

```
docker run -it -e DATABASE_DRIVER='mysql' \
-e DATABASE_ENCODING='utf8' \
-e SAMPLE_DATA_LENGTH='100' \
-e DATABASE_HOST='host.docker.internal' \
-e DATABASE_PORT='3306' \
-e DATABASE_NAME='compalex_dev' \
-e DATABASE_USER='root' \
-e DATABASE_PASSWORD='password' \
-e DATABASE_DESCRIPTION='Developer database' \
-e DATABASE_HOST_SECONDARY='host.docker.internal' \
-e DATABASE_PORT_SECONDARY='3306' \
-e DATABASE_NAME_SECONDARY='compalex_prod' \
-e DATABASE_USER_SECONDARY='root' \
-e DATABASE_PASSWORD_SECONDARY='password' \
-e DATABASE_DESCRIPTION_SECONDARY='Production database' \
-p 8000:8000 dlevsha/compalex
```

You need to change variables for your own

`DATABASE_DRIVER` - database driver, possible value

- `mysql` - for MySQL database
- `pgsql` - for PostgreSQL database
- `dblib` - for Microsoft SQL Server database
- `oci` - for Oracle database

`DATABASE_HOST` and `DATABASE_HOST_SECONDARY` - database host name or IP for first and second server

If your compared DB run locally:

- for [MacOS](https://docs.docker.com/docker-for-mac/networking/) and [Windows](https://docs.docker.com/docker-for-windows/networking/)user: use `host.docker.internal` instead of `localhost` in `DATABASE_HOST` and `DATABASE_HOST_SECONDARY` param. Because we run script inside container we need to use Host machine IP for connection.
- for [Linux](https://docs.docker.com/network/host/) user: use `--network host` option and `localhost` in `DATABASE_HOST` and `DATABASE_HOST_SECONDARY` param.

If you connect to DB outside your machine (external IP) use: `-e DATABASE_HOST='[Your external IP]'`.

`DATABASE_PORT` and `DATABASE_PORT_SECONDARY` - database port for first and second server

Default ports for DB:

- `3306` - Mysql
- `5432` - PostgreSQL
- `1433` - MSSQL
- `1521` - Oracle

`DATABASE_NAME` and `DATABASE_NAME_SECONDARY` - first and second database name

`DATABASE_USER` / `DATABASE_PASSWORD` and `DATABASE_USER_SECONDARY` / `DATABASE_PASSWORD_SECONDARY` - login and password to access your databases

`DATABASE_DESCRIPTION` and `DATABASE_DESCRIPTION_SECONDARY` - server description (not necessary). For information only. These names will display as a database name.

You can also use `docker-compose.yml`.

```
version: "3.7"

services:
  compalex:
    image: dlevsha/compalex
    container_name: compalex
    environment:
      - DATABASE_DRIVER=mysql
      - DATABASE_ENCODING=utf8
      - SAMPLE_DATA_LENGTH=100
      - DATABASE_HOST=host.docker.internal
      - DATABASE_PORT=3306
      - DATABASE_NAME=compalex_dev
      - DATABASE_USER=root
      - DATABASE_PASSWORD=password
      - DATABASE_DESCRIPTION=Developer database
      - DATABASE_HOST_SECONDARY=host.docker.internal
      - DATABASE_PORT_SECONDARY=3306
      - DATABASE_NAME_SECONDARY=compalex_prod
      - DATABASE_USER_SECONDARY=root
      - DATABASE_PASSWORD_SECONDARY=password
      - DATABASE_DESCRIPTION_SECONDARY=Production database
    ports:
      - "8000:8000"

```

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

[](#requirements)

If you prefer use Compalex as PHP script please read instruction bellow.

Compalex is only supported by PHP 5.4 and up with PDO extension.

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

[](#installation)

```
$ git clone https://github.com/dlevsha/compalex.git
$ cd compalex

```

Open `.environment`. You'll see configuration params

```
[ Main settings ]
; Possible DATABASE_DRIVER: 'mysql', 'pgsql', 'dblib', 'oci'.
; Please use 'dblib' for Microsoft SQL Server
DATABASE_DRIVER = mysql
DATABASE_ENCODING = utf8
SAMPLE_DATA_LENGTH = 100

[ Primary connection params ]
DATABASE_HOST = localhost
DATABASE_PORT = 3306
DATABASE_NAME = compalex_dev
DATABASE_USER = root
DATABASE_PASSWORD =
DATABASE_DESCRIPTION = Developer database

[ Secondary connection params ]
DATABASE_HOST_SECONDARY = localhost
DATABASE_PORT_SECONDARY = 3306
DATABASE_NAME_SECONDARY = compalex_prod
DATABASE_USER_SECONDARY = root
DATABASE_PASSWORD_SECONDARY =
DATABASE_DESCRIPTION_SECONDARY = Production database
```

where

`DATABASE_DRIVER` - database driver, possible value

- `mysql` - for MySQL database
- `pgsql` - for PostgreSQL database
- `dblib` - for Microsoft SQL Server database
- `oci` - for Oracle database

`[ Primary connection params ]` and `[ Secondary connection params ]`sections describes settings for first and second databases.

Where

`DATABASE_HOST` and `DATABASE_HOST_SECONDARY` - database host name or IP for first and second server

`DATABASE_PORT` and `DATABASE_PORT_SECONDARY` - database port for first and second server

Default ports:

- `3306` - Mysql
- `5432` - PostgreSQL
- `1433` - MSSQL
- `1521` - Oracle

`DATABASE_NAME` and `DATABASE_NAME_SECONDARY` - first and second database name

`DATABASE_USER` / `DATABASE_PASSWORD` and `DATABASE_USER_SECONDARY` / `DATABASE_PASSWORD_SECONDARY` - login and password to access your databases

`DATABASE_DESCRIPTION` and `DATABASE_DESCRIPTION_SECONDARY` - server description (not necessary). For information only. These names will display as a database name.

Inside `compalex` directory run

```
$ php -S localhost:8000

```

Now open your browser and type `http://localhost:8000/`

You'll see database schema of two compared databases.

-

[![Database Compare Panel](https://cloud.githubusercontent.com/assets/1639576/9703302/1327b858-5488-11e5-856a-96b139c7b938.png)](https://cloud.githubusercontent.com/assets/1639576/9703302/1327b858-5488-11e5-856a-96b139c7b938.png)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#)

You can run this script in terminal (for example, if you don't have direct connection to database).

I recommend [eLinks](https://en.wikipedia.org/wiki/ELinks) (free text-based console web browser) because it supports HTML-formatting and colors.

Install the script and run web-server as described above on your server.

Then run:

```
$ elinks http://localhost:8000

```

You'll see database schema in your terminal

[![Database schema in terminal](https://cloud.githubusercontent.com/assets/1639576/10304652/248de29e-6c24-11e5-863b-c94bf337f47d.png)](https://cloud.githubusercontent.com/assets/1639576/10304652/248de29e-6c24-11e5-863b-c94bf337f47d.png)

Sometimes you have only SSH access to remote database server and you can't open port for external connections. In this case you can use port forwarding via SSH

```
ssh -L 1522:localhost:1521 [user name]@[remote host 1]
ssh -L 1523:localhost:1521 [user name]@[remote host 2]

```

This command will forward `1521` port from remote servers to local `1522` and `1523` respectively.

LICENSE
-------

[](#license)

Copyright (c) 2021, Levsha Dmitry

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

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

3805d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/73b35d8b29e5f10707a5c16fee09939425ba24fb1d19566806d39e64d7b818fe?d=identicon)[dlevsha](/maintainers/dlevsha)

---

Top Contributors

[![dlevsha](https://avatars.githubusercontent.com/u/1639576?v=4)](https://github.com/dlevsha "dlevsha (35 commits)")[![amarjitsingh52922](https://avatars.githubusercontent.com/u/47297185?v=4)](https://github.com/amarjitsingh52922 "amarjitsingh52922 (1 commits)")[![gareth-ib](https://avatars.githubusercontent.com/u/29517750?v=4)](https://github.com/gareth-ib "gareth-ib (1 commits)")[![Georgynet](https://avatars.githubusercontent.com/u/4614965?v=4)](https://github.com/Georgynet "Georgynet (1 commits)")[![Vaalon](https://avatars.githubusercontent.com/u/12898787?v=4)](https://github.com/Vaalon "Vaalon (1 commits)")

---

Tags

compared-databasesdatabase-managementdatabase-migrationsdatabase-schemadatabase-structuremssql-diffmysql-diffmysqldiffpgsql-httppostgresql-diffcompare database schemascompare databasesdatabase diffdatabase schema diff

### Embed Badge

![Health badge](/badges/dlevsha-compalex/health.svg)

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

###  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.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

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

Reliese Components for Laravel Framework code generation.

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

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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