PHPackages                             1manfactory/compare\_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. [CLI &amp; Console](/categories/cli)
4. /
5. 1manfactory/compare\_db

ActiveProject[CLI &amp; Console](/categories/cli)

1manfactory/compare\_db
=======================

A CLI tool to compare MySQL/MariaDB database schema definitions between development and production environments.

v1.1.2(12mo ago)1123MITPHPPHP &gt;=7.4

Since Mar 25Pushed 12mo ago1 watchersCompare

[ Source](https://github.com/1manfactory/compare_db)[ Packagist](https://packagist.org/packages/1manfactory/compare_db)[ RSS](/packages/1manfactory-compare-db/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (6)Used By (0)

compare\_db
===========

[](#compare_db)

`compare_db` is a command-line PHP tool that compares the database schema definitions between your development and production MySQL/MariaDB environments. The tool dynamically compares all non-system databases between both environments. It loads environment variables from a `.env` file, establishes database connections using PDO, retrieves the `CREATE` statements for tables, views, procedures, and functions from each database, and highlights any differences in the terminal output.

Features
--------

[](#features)

- Loads environment variables from a `.env` file.
- Connects to MySQL/MariaDB databases via PDO.
- Dynamically retrieves a list of non-system databases (excluding `mysql`, `information_schema`, `performance_schema`, and `sys`).
- Retrieves `CREATE` statements for:
    - Tables (excluding those with `_mv` or `_pv` suffixes)
    - Views
    - Stored Procedures
    - Functions
- Compares schema definitions across all common databases between development and production.
- Outputs color-coded differences in the console.
- Optionally executes additional dump scripts if discrepancies are found (customizable in the code).

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

[](#requirements)

- PHP 7.4 or higher.
- MySQL/MariaDB databases.
- (Optional) Composer if you choose to manage dependencies or autoloading.

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

[](#installation)

1. **Clone the repository:**

    ```
    git clone https://your.repository.url.git
    cd your-repository-folder
    ```
2. **Make the script executable:**

    ```
    chmod +x compare_db
    ```
3. **Create your `.env` file:**

    Copy the `.env.example` file to `.env` and update the database credentials accordingly.

.env Configuration
------------------

[](#env-configuration)

Your `.env` file should contain the necessary settings for both development and production environments. For example:

```
# Development Database
DEV_DB_HOST=localhost
DEV_DB_USER=your_dev_user
DEV_DB_PASS=your_dev_password

# Production Database
PROD_DB_HOST=production_host
PROD_DB_USER=your_prod_user
PROD_DB_PASS=your_prod_password
```

> **Note:** The script automatically detects all non-system databases on both environments. Only databases common to both environments will be compared.

Usage
-----

[](#usage)

Run the script from the command line:

```
./compare_db
```

The script will:

- Load the environment variables.
- Establish connections to both the development and production database servers.
- Retrieve a list of all non-system databases from both environments.
- For each database common to both environments, retrieve and compare the `CREATE` definitions for tables, views, procedures, and functions.
- Output any differences using color-coded messages in the terminal.
- Optionally execute additional dump scripts if discrepancies are detected (this behavior can be customized in the code).

Troubleshooting
---------------

[](#troubleshooting)

- **.env file issues:** Ensure your `.env` file is in the same directory as the script and correctly configured.
- **Database connection errors:** Verify that your credentials are correct and that both database servers are accessible.
- **Permissions:** Confirm that the script has executable permissions.

Contributing
------------

[](#contributing)

Contributions and improvements are welcome! Please open an issue or submit a pull request if you have any suggestions or bug fixes.

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

29

—

LowBetter than 63% of packages

Maintenance50

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

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

Every ~0 days

Total

5

Last Release

361d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6a5913e5af48c78047823109e7de4db4065b9b630e0dc8fa9b4732a3d71e33b7?d=identicon)[1manfactory](/maintainers/1manfactory)

### Embed Badge

![Health badge](/badges/1manfactory-compare-db/health.svg)

```
[![Health](https://phpackages.com/badges/1manfactory-compare-db/health.svg)](https://phpackages.com/packages/1manfactory-compare-db)
```

###  Alternatives

[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.6k324.1M7.0k](/packages/nunomaduro-collision)[wp-cli/wp-cli

WP-CLI framework

5.1k16.6M256](/packages/wp-cli-wp-cli)[consolidation/annotated-command

Initialize Symfony Console commands from annotated command class methods.

22568.5M16](/packages/consolidation-annotated-command)[chi-teck/drupal-code-generator

Drupal code generator

26946.8M4](/packages/chi-teck-drupal-code-generator)[consolidation/config

Provide configuration services for a commandline tool.

16959.8M14](/packages/consolidation-config)[seld/cli-prompt

Allows you to prompt for user input on the command line, and optionally hide the characters they type

24725.5M14](/packages/seld-cli-prompt)

PHPackages © 2026

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