1manfactory/compare_db
最新稳定版本:v1.1.2
Composer 安装命令:
composer create-project 1manfactory/compare_db
包简介
A CLI tool to compare MySQL/MariaDB database schema definitions between development and production environments.
README 文档
README
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
- Loads environment variables from a
.envfile. - Connects to MySQL/MariaDB databases via PDO.
- Dynamically retrieves a list of non-system databases (excluding
mysql,information_schema,performance_schema, andsys). - Retrieves
CREATEstatements for:- Tables (excluding those with
_mvor_pvsuffixes) - Views
- Stored Procedures
- Functions
- Tables (excluding those with
- 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
- PHP 7.4 or higher.
- MySQL/MariaDB databases.
- (Optional) Composer if you choose to manage dependencies or autoloading.
Installation
-
Clone the repository:
git clone https://your.repository.url.git cd your-repository-folder -
Make the script executable:
chmod +x compare_db
-
Create your
.envfile:Copy the
.env.examplefile to.envand update the database credentials accordingly.
.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
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
CREATEdefinitions 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
- .env file issues: Ensure your
.envfile 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
Contributions and improvements are welcome! Please open an issue or submit a pull request if you have any suggestions or bug fixes.
License
This project is licensed under the MIT License. See the LICENSE file for details.
统计信息
- 总下载量: 104
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-25