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(1y ago)1123MITPHPPHP &gt;=7.4

Since Mar 25Pushed 1y 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 1mo ago

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 60% of packages

Maintenance46

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity41

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

414d 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

[wp-cli/wp-cli

WP-CLI framework

5.0k17.2M320](/packages/wp-cli-wp-cli)[consolidation/annotated-command

Initialize Symfony Console commands from annotated command class methods.

22569.8M19](/packages/consolidation-annotated-command)[chi-teck/drupal-code-generator

Drupal code generator

26947.8M5](/packages/chi-teck-drupal-code-generator)[seld/cli-prompt

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

24725.8M17](/packages/seld-cli-prompt)[illuminate/console

The Illuminate Console package.

12944.1M5.1k](/packages/illuminate-console)[php-tui/php-tui

Comprehensive TUI library heavily influenced by Ratatui

589747.0k6](/packages/php-tui-php-tui)

PHPackages © 2026

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