{"id":22702512,"url":"https://github.com/vielhuber/magicreplace","last_synced_at":"2026-03-17T12:33:12.907Z","repository":{"id":62544082,"uuid":"85520835","full_name":"vielhuber/magicreplace","owner":"vielhuber","description":"✨ A search replace tool for migrating databases. ✨","archived":false,"fork":false,"pushed_at":"2026-01-21T08:46:29.000Z","size":7166,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-04T04:52:39.236Z","etag":null,"topics":["sql"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vielhuber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2017-03-20T00:57:35.000Z","updated_at":"2026-01-21T08:46:26.000Z","dependencies_parsed_at":"2024-04-23T14:17:35.845Z","dependency_job_id":"c13e4647-4f1f-4b07-9a3f-adffcb6f21a6","html_url":"https://github.com/vielhuber/magicreplace","commit_stats":{"total_commits":87,"total_committers":2,"mean_commits":43.5,"dds":0.02298850574712641,"last_synced_commit":"9c50198f86d70736adbfe11f36aea8ccf76042f4"},"previous_names":[],"tags_count":58,"template":false,"template_full_name":null,"purl":"pkg:github/vielhuber/magicreplace","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vielhuber%2Fmagicreplace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vielhuber%2Fmagicreplace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vielhuber%2Fmagicreplace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vielhuber%2Fmagicreplace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vielhuber","download_url":"https://codeload.github.com/vielhuber/magicreplace/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vielhuber%2Fmagicreplace/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30623662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T11:26:08.186Z","status":"ssl_error","status_checked_at":"2026-03-17T11:24:37.311Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["sql"],"created_at":"2024-12-10T07:13:46.369Z","updated_at":"2026-03-17T12:33:12.902Z","avatar_url":"https://github.com/vielhuber.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![build status](https://github.com/vielhuber/magicreplace/actions/workflows/ci.yml/badge.svg)](https://github.com/vielhuber/magicreplace/actions)\n\n# ✨ magicreplace ✨\n\nmagicreplace is a search replace tool for migrating databases.\n\n## Intro\n\n### The problem\n\nWhen moving databases, usually the url environment also changes.\nIf the URL is hardcoded in the database (like WordPress [does](https://make.wordpress.org/core/handbook/contribute/design-decisions/#absolute-versus-relative-urls)), those URLs have to be changed.\nIf you now do a search and replace on your entire database to change the URLs,\nyou will corrupt data that has been serialized. Just try out\n\n```php\nunserialize(str_replace('www.foo.tld', 'www.barrr.tld', serialize('url=www.foo.tld')));\n```\n\nand you will get an ugly error.\n\n### There already exist cool tools that solve this issue, for example...\n\n-   [Velvet Blues Update URLs](https://wordpress.org/plugins/velvet-blues-update-urls/)\n-   [Better Search Replace](https://wordpress.org/plugins/better-search-replace/)\n-   [Suchen \u0026 Ersetzen](https://de.wordpress.org/plugins/search-and-replace/)\n-   [WP Migrate DB](https://de.wordpress.org/plugins/wp-migrate-db/)\n-   [WP-CLI's search-replace](http://wp-cli.org/commands/search-replace/)\n-   [Search-Replace-DB](https://github.com/interconnectit/Search-Replace-DB)\n-   [SerPlace](http://pixelentity.com/wordpress-search-replace-domain/)\n\n### How is magicreplace different from those tools?\n\n-   Fast (~5sec runtime on 100mb database file with 300.000 rows)\n-   Lightweight: Only \u003c10kb in size\n-   Works also on big files with small memory limit settings\n-   File based: Does not need a database or a wp installation - works on plain (sql) files\n-   Local usage: Does not need a remote server or a webservice\n-   Multi replace: Does multiple replaces\n-   Considers edge cases: Can handle objects and even references\n-   Ignores classes that are not available at runtime\n-   Can be used either with the command line or as a class\n-   Acts carefully: If serialization fails, nothing is changed\n-   Never changes data (out of bound ints are preserved, auto generated dates are not updated)\n-   Does its work in junks to overcome php limits\n-   Supports replacements in special base64 strings (e.g. in BeTheme)\n\n### Disclaimer\n\nThis does not release you from taking backups. Use this script at your own risk!\n\n## Command line\n\n### Requirements\n\n##### Mac\n\n```\nbrew install coreutils\n```\n\n##### Windows\n\nRuns out of the box with [WSL/WSL2](https://docs.microsoft.com/en-us/windows/wsl/about)/[Cygwin](https://cygwin.com/install.html).\n\n##### Linux\n\n–\n\n### Installation\n\n```\nwget https://raw.githubusercontent.com/vielhuber/magicreplace/main/src/magicreplace.php\n```\n\n### Usage\n\n```\nphp magicreplace.php input.sql output.sql search-1 replace-1 search-2 replace-2\n```\n\n## Class\n\n### Installation\n\n```\ncomposer require vielhuber/magicreplace\n```\n\n### Usage\n\n```php\n\u003c?php\nrequire __DIR__ . '/vendor/autoload.php';\nuse vielhuber\\magicreplace\\magicreplace;\nmagicreplace::run('input.sql', 'output.sql', ['search-1' =\u003e 'replace-2', 'search-2' =\u003e 'replace-2']);\n```\n\n## Recommended replace strategy\n\nIf you want for example to replace http://www.foo.tld with https://www.bar.tld, the safest method to do so is with the following replacements (in the given order):\n\n-   `http://www.foo.tld` `https://www.bar.tld`\n-   `https://www.foo.tld` `https://www.bar.tld`\n-   `http://foo.tld` `https://www.bar.tld`\n-   `https://foo.tld` `https://www.bar.tld`\n-   `www.foo.tld` `www.bar.tld`\n-   `foo.tld` `bar.tld`\n\n## Testing\n\nJust place these 3 files in a (optionally nested) subfolder of `tests/data`:\n\n-   `input.sql`: The desired input file\n-   `output.sql`: The desired output file\n-   `settings.sql`: Define your replacements\n\nExample `settings.sql` file:\n\n```\n{\n    \"replace\": {\n        \"http://www.foo.tld\": \"https://www.bar.tld\",\n        \"https://www.foo.tld\": \"https://www.bar.tld\"\n    }\n}\n```\n\nIf a test fails, the expected output is stored in `expected.sql`.\n\nYou can even auto generate test cases (that compares magicreplace to [Search-Replace-DB](https://github.com/interconnectit/Search-Replace-DB) and only gives you the diff) if you omit `input.sql` and `output.sql` and define a mysql database to dump from locally. Example `settings.sql` file:\n\n```\n{\n    \"source\": {\n        \"host\": \"localhost\",\n        \"port\": \"3306\",\n        \"database\": \"xxx\",\n        \"username\": \"xxx\",\n        \"password\": \"xxx\",\n    },\n    \"replace\": {\n        \"http://www.foo.tld\": \"https://www.bar.tld\",\n        \"https://www.foo.tld\": \"https://www.bar.tld\"\n    }\n}\n```\n\n`input.sql` and `output.sql` then get generated automatically. After you rerun the tests, these generated files are used. If you want to generate them again, just delete them before running the test. You also can provide a `whitelist.sql` file that includes all lines from `input.sql` that should be ignored (e.g. where magicreplace acts differently from Search-Replace-DB).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvielhuber%2Fmagicreplace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvielhuber%2Fmagicreplace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvielhuber%2Fmagicreplace/lists"}