{"id":36951196,"url":"https://github.com/mathsgod/mysql-schema-migrate","last_synced_at":"2026-02-26T06:03:09.326Z","repository":{"id":327711751,"uuid":"1110452802","full_name":"mathsgod/mysql-schema-migrate","owner":"mathsgod","description":null,"archived":false,"fork":false,"pushed_at":"2025-12-05T08:26:54.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-14T00:02:31.256Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mathsgod.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-05T08:05:09.000Z","updated_at":"2025-12-05T08:11:32.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/mathsgod/mysql-schema-migrate","commit_stats":null,"previous_names":["mathsgod/mysql-schema-migrate"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/mathsgod/mysql-schema-migrate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fmysql-schema-migrate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fmysql-schema-migrate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fmysql-schema-migrate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fmysql-schema-migrate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathsgod","download_url":"https://codeload.github.com/mathsgod/mysql-schema-migrate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fmysql-schema-migrate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29849830,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T22:37:40.667Z","status":"online","status_checked_at":"2026-02-26T02:00:06.774Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-13T12:06:30.682Z","updated_at":"2026-02-26T06:03:09.320Z","avatar_url":"https://github.com/mathsgod.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MySQL Schema Migrate\n\nExport and import MySQL database schema to/from JSON format.\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![PHP Version](https://img.shields.io/badge/PHP-%3E%3D8.1-8892BF.svg)](https://www.php.net/)\n\n## Features\n\n- Export complete MySQL database schema to JSON format\n- Import schema from JSON with intelligent diff detection\n- Supports:\n  - Tables (with columns, primary keys, unique keys, foreign keys, indexes)\n  - Views\n  - Triggers\n  - Functions\n  - Procedures\n  - Events\n- Smart schema diff: uses `ALTER TABLE` for existing tables instead of recreating\n- Dry-run mode to preview SQL without executing\n- CLI tool with easy-to-use options\n- Can be used as a PHP library\n\n## Requirements\n\n- PHP \u003e= 8.1\n- PDO extension\n- PDO MySQL extension\n- JSON extension\n\n## Installation\n\n### Via Composer\n\n```bash\ncomposer require mathsgod/mysql-schema-migrate\n```\n\n### Global Installation\n\n```bash\ncomposer global require mathsgod/mysql-schema-migrate\n```\n\n## Usage\n\n### Export Command\n\n```bash\n# Basic usage\n./vendor/bin/mysql-schema-migrate export -u username -d database_name\n\n# With password\n./vendor/bin/mysql-schema-migrate export -u username -p password -d database_name\n\n# Specify host and port\n./vendor/bin/mysql-schema-migrate export -H localhost -P 3306 -u username -p password -d database_name\n\n# Output to file\n./vendor/bin/mysql-schema-migrate export -u username -d database_name -o schema.json\n\n# With custom charset\n./vendor/bin/mysql-schema-migrate export -u username -d database_name -c utf8mb4\n```\n\n#### Export Options\n\n| Option | Short | Description | Default |\n|--------|-------|-------------|---------|\n| `--host` | `-H` | MySQL host | `localhost` |\n| `--port` | `-P` | MySQL port | `3306` |\n| `--database` | `-d` | Database name | (required) |\n| `--username` | `-u` | MySQL username | (required) |\n| `--password` | `-p` | MySQL password | (empty) |\n| `--charset` | `-c` | Connection charset | `utf8mb4` |\n| `--output` | `-o` | Output file path | stdout |\n\n### Import Command\n\n```bash\n# Basic import\n./vendor/bin/mysql-schema-migrate import -u username -d database_name schema.json\n\n# Dry-run mode (preview SQL without executing)\n./vendor/bin/mysql-schema-migrate import --dry-run -u username -d database_name schema.json\n\n# Dry-run with SQL output to file\n./vendor/bin/mysql-schema-migrate import --dry-run -o output.sql -u username -d database_name schema.json\n\n# Allow dropping columns/tables/objects\n./vendor/bin/mysql-schema-migrate import --allow-drop -u username -d database_name schema.json\n\n# Keep original DEFINER (default: reset to CURRENT_USER)\n./vendor/bin/mysql-schema-migrate import --keep-definer -u username -d database_name schema.json\n\n# Import only specific object types\n./vendor/bin/mysql-schema-migrate import --only=tables,views -u username -d database_name schema.json\n```\n\n#### Import Options\n\n| Option | Short | Description | Default |\n|--------|-------|-------------|---------|\n| `--host` | `-H` | MySQL host | `localhost` |\n| `--port` | `-P` | MySQL port | `3306` |\n| `--database` | `-d` | Database name | (required) |\n| `--username` | `-u` | MySQL username | (required) |\n| `--password` | `-p` | MySQL password | (empty) |\n| `--charset` | `-c` | Connection charset | `utf8mb4` |\n| `--dry-run` | | Only generate SQL without executing | `false` |\n| `--output-file` | `-o` | Output SQL to file (use with --dry-run) | |\n| `--allow-drop` | | Allow dropping columns, tables, and objects | `false` |\n| `--keep-definer` | | Keep original DEFINER | `false` |\n| `--only` | | Only process specific types (comma-separated) | all |\n\n#### Import Behavior\n\n- **Tables**: Uses `ALTER TABLE` for existing tables (ADD/MODIFY/DROP COLUMN, index changes)\n- **Views**: Uses `CREATE OR REPLACE VIEW`\n- **Functions/Procedures/Triggers/Events**: Uses `DROP IF EXISTS` + `CREATE`\n- **DEFINER**: Reset to `CURRENT_USER` by default (use `--keep-definer` to preserve)\n- **Foreign Keys**: Handled separately to avoid dependency issues\n\n### As a Library\n\n```php\n\u003c?php\n\nuse MysqlSchemaMigrate\\Exporter;\nuse MysqlSchemaMigrate\\Importer;\n\n// Export schema\n$exporter = new Exporter(\n    host: 'localhost',\n    database: 'my_database',\n    username: 'root',\n    password: 'password',\n    port: 3306,\n    charset: 'utf8mb4'\n);\n\n// Get schema as array\n$schema = $exporter-\u003eexport();\n\n// Get schema as JSON string\n$json = $exporter-\u003etoJson();\n\n// Save to file\nfile_put_contents('schema.json', $json);\n\n// Import schema\n$importer = new Importer(\n    host: 'localhost',\n    database: 'target_database',\n    username: 'root',\n    password: 'password',\n    port: 3306,\n    charset: 'utf8mb4'\n);\n\n// Import from file (dry-run)\n$statements = $importer-\u003eimportFromFile(\n    filePath: 'schema.json',\n    dryRun: true,\n    allowDrop: false,\n    keepDefiner: false,\n    only: [] // empty = all types\n);\n\n// Get formatted SQL for review\n$sql = $importer-\u003eformatSqlForFile();\nfile_put_contents('migration.sql', $sql);\n\n// Import and execute\n$statements = $importer-\u003eimportFromFile(\n    filePath: 'schema.json',\n    dryRun: false,\n    allowDrop: true\n);\n```\n\n## Output Format\n\nThe exported JSON contains the following structure:\n\n```json\n{\n    \"tables\": [\n        {\n            \"name\": \"users\",\n            \"columns\": [\n                {\n                    \"name\": \"id\",\n                    \"type\": \"int\",\n                    \"nullable\": false,\n                    \"default\": null,\n                    \"auto_increment\": true,\n                    \"unsigned\": true\n                },\n                {\n                    \"name\": \"email\",\n                    \"type\": \"varchar\",\n                    \"nullable\": false,\n                    \"default\": null,\n                    \"auto_increment\": false,\n                    \"length\": 255,\n                    \"charset\": \"utf8mb4\",\n                    \"collation\": \"utf8mb4_unicode_ci\"\n                }\n            ],\n            \"primary_key\": [\"id\"],\n            \"unique_keys\": [\n                {\n                    \"name\": \"users_email_unique\",\n                    \"columns\": [\"email\"]\n                }\n            ],\n            \"foreign_keys\": [],\n            \"indexes\": [],\n            \"engine\": \"InnoDB\",\n            \"charset\": \"utf8mb4\",\n            \"collation\": \"utf8mb4_unicode_ci\",\n            \"comment\": null\n        }\n    ],\n    \"views\": [],\n    \"triggers\": [],\n    \"functions\": [],\n    \"procedures\": [],\n    \"events\": []\n}\n```\n\n## License\n\nMIT License. See [LICENSE](LICENSE) for more information.\n\n## Author\n\nRaymond Chong (mathsgod@yahoo.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathsgod%2Fmysql-schema-migrate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathsgod%2Fmysql-schema-migrate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathsgod%2Fmysql-schema-migrate/lists"}