{"id":48441535,"url":"https://github.com/stellarwp/migrations","last_synced_at":"2026-04-06T15:31:23.193Z","repository":{"id":334229178,"uuid":"1104771927","full_name":"stellarwp/migrations","owner":"stellarwp","description":"A library providing its users with the required tools to create their WP migration! Provides a UI, WP-CLI and REST integration out of the box!","archived":false,"fork":false,"pushed_at":"2026-02-16T17:51:32.000Z","size":994,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-16T21:06:31.571Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stellarwp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","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-11-26T17:03:52.000Z","updated_at":"2026-02-16T17:51:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/stellarwp/migrations","commit_stats":null,"previous_names":["stellarwp/migrations"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stellarwp/migrations","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stellarwp%2Fmigrations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stellarwp%2Fmigrations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stellarwp%2Fmigrations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stellarwp%2Fmigrations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stellarwp","download_url":"https://codeload.github.com/stellarwp/migrations/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stellarwp%2Fmigrations/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31477946,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-06T14:34:32.243Z","status":"ssl_error","status_checked_at":"2026-04-06T14:34:31.723Z","response_time":112,"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":[],"created_at":"2026-04-06T15:31:22.502Z","updated_at":"2026-04-06T15:31:23.188Z","avatar_url":"https://github.com/stellarwp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Migrations\n\nA batched database migrations library for WordPress plugins powered by [Shepherd](https://github.com/stellarwp/shepherd).\n\n[![PHP Compatibility](https://github.com/stellarwp/migrations/actions/workflows/compatibility.yml/badge.svg)](https://github.com/stellarwp/migrations/actions/workflows/compatibility.yml)\n[![PHP Code Standards](https://github.com/stellarwp/migrations/actions/workflows/phpcs.yml/badge.svg)](https://github.com/stellarwp/migrations/actions/workflows/phpcs.yml)\n[![PHPStan](https://github.com/stellarwp/migrations/actions/workflows/phpstan.yml/badge.svg)](https://github.com/stellarwp/migrations/actions/workflows/phpstan.yml)\n[![General Code Standards](https://github.com/stellarwp/migrations/actions/workflows/standards.yml/badge.svg)](https://github.com/stellarwp/migrations/actions/workflows/standards.yml)\n[![PHP Tests](https://github.com/stellarwp/migrations/actions/workflows/tests-php.yml/badge.svg)](https://github.com/stellarwp/migrations/actions/workflows/tests-php.yml)\n\n## Features\n\n- **Batched execution** - Process large datasets incrementally without timeouts.\n- **Automatic rollback** - Failed migrations trigger automatic rollback via `down()` (status: `FAILED`).\n- **Manual rollback** - Completed migrations can be manually rolled back (status: `REVERTED`).\n- **Activity logging** - All migration activity is logged to a database table.\n- **Automatic log cleanup** - Old logs are automatically cleaned up after a configurable retention period.\n- **Extensible hooks** - Actions and filters for custom behavior at each stage.\n- **WP-CLI integration** - Full CLI support for running, rolling back, and monitoring migrations.\n\n## Quick Start\n\n```php\nuse StellarWP\\Migrations\\Config;\nuse StellarWP\\Migrations\\Provider;\nuse StellarWP\\Migrations\\Registry;\nuse StellarWP\\Migrations\\Abstracts\\Migration_Abstract;\nuse StellarWP\\Migrations\\Enums\\Operation;\n\n// Configure the library.\nConfig::set_container( $container );\nConfig::set_hook_prefix( 'my_plugin' );\n\n// Register the provider.\n$container-\u003eget( Provider::class )-\u003eregister();\n\n// Create a migration.\nclass Rename_Meta_Key extends Migration_Abstract {\n    public function get_label(): string {\n        return 'Rename Meta Key';\n    }\n\n    public function get_description(): string {\n        return 'Renames old_key to new_key in post meta.';\n    }\n\n    public function is_applicable(): bool {\n        return true;\n    }\n\n    public function is_up_done(): bool {\n        global $wpdb;\n        return ! (int) $wpdb-\u003eget_var(\n            $wpdb-\u003eprepare(\n                'SELECT COUNT(*) FROM %i WHERE meta_key = %s',\n                $wpdb-\u003epostmeta,\n                'old_key'\n            )\n        );\n    }\n\n    public function is_down_done(): bool {\n        global $wpdb;\n        return ! (int) $wpdb-\u003eget_var(\n            $wpdb-\u003eprepare(\n                'SELECT COUNT(*) FROM %i WHERE meta_key = %s',\n                $wpdb-\u003epostmeta,\n                'new_key'\n            )\n        );\n    }\n\n    public function get_total_items( ?Operation $operation = null ): int {\n        global $wpdb;\n        $key = ( $operation ?? Operation::UP() )-\u003eequals( Operation::DOWN() ) ? 'new_key' : 'old_key';\n        return (int) $wpdb-\u003eget_var(\n            $wpdb-\u003eprepare(\n                'SELECT COUNT(*) FROM %i WHERE meta_key = %s',\n                $wpdb-\u003epostmeta,\n                $key\n            )\n        );\n    }\n\n    public function get_default_batch_size(): int {\n        return 100;\n    }\n\n    public function up( int $batch, int $batch_size ): void {\n        global $wpdb;\n        $wpdb-\u003equery(\n            $wpdb-\u003eprepare(\n                'UPDATE %i SET meta_key = %s WHERE meta_key = %s LIMIT %d',\n                $wpdb-\u003epostmeta,\n                'new_key',\n                'old_key',\n                $batch_size\n            )\n        );\n    }\n\n    public function down( int $batch, int $batch_size ): void {\n        global $wpdb;\n        $wpdb-\u003equery(\n            $wpdb-\u003eprepare(\n                'UPDATE %i SET meta_key = %s WHERE meta_key = %s LIMIT %d',\n                $wpdb-\u003epostmeta,\n                'old_key',\n                'new_key',\n                $batch_size\n            )\n        );\n    }\n}\n\n// Register the migration with a unique ID.\n$registry = Config::get_container()-\u003eget( Registry::class );\n$registry-\u003eregister( 'my_plugin_rename_meta_key', Rename_Meta_Key::class );\n```\n\n## Logging\n\nAdd custom logs to track migration progress and debug issues:\n\n```php\npublic function up( int $batch, int $batch_size ): void {\n    $logger = Config::get_container()-\u003eget( Logger::class );\n\n    $logger-\u003einfo( 'Starting batch processing.', [ 'batch' =\u003e $batch ] );\n\n    // ... do migration work ...\n\n    if ( $some_warning_condition ) {\n        $logger-\u003ewarning( 'Found invalid data.', [ 'record_id' =\u003e $id ] );\n    }\n}\n```\n\nAvailable log levels: `info()`, `warning()`, `error()`, `debug()`\n\n**Log Cleanup:**\n\nOld migration logs are automatically cleaned up after 180 days (configurable via the `stellarwp_migrations_{prefix}_log_retention_days` filter). See [Getting Started](./docs/getting-started.md#log-cleanup) for details.\n\n## WP-CLI\n\nManage migrations from the command line:\n\n```bash\n# List all registered migrations\nwp my-plugin migrations list\n\n# Run a specific migration\nwp my-plugin migrations run my_migration_id\n\n# Rollback a migration\nwp my-plugin migrations rollback my_migration_id\n\n# View execution history\nwp my-plugin migrations executions my_migration_id\n\n# View logs for an execution\nwp my-plugin migrations logs 123 --type=error\n```\n\nThe command prefix (`my-plugin` above) is derived from your configured hook prefix.\n\nSee [CLI Reference](./docs/cli.md) for full command documentation.\n\n## Documentation\n\n- [Getting Started](./docs/getting-started.md) - Installation and basic usage\n- [Migration Contract](./docs/migration-contract.md) - Full API reference\n- [Admin UI Reference](./docs/admin-ui.md) - Admin interface for managing migrations\n- [CLI Reference](./docs/cli.md) - WP-CLI commands and usage\n- [REST API Reference](./docs/rest-api.md) - REST API endpoints for programmatic access\n- [Programmatic Scheduling](./docs/programmatic-scheduling.md) - How to programmatically schedule migrations\n- [Hooks Reference](./docs/hooks.md) - Available actions and filters\n- [Tests](./docs/test.md) - Test setup instructions\n\n## Contributing\n\nWe welcome contributions. Please see our contributing guidelines for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstellarwp%2Fmigrations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstellarwp%2Fmigrations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstellarwp%2Fmigrations/lists"}