{"id":43106072,"url":"https://github.com/sidworks-dev/sw-plugin-database-sync","last_synced_at":"2026-04-04T22:36:47.386Z","repository":{"id":335088906,"uuid":"1144039409","full_name":"sidworks-dev/sw-plugin-database-sync","owner":"sidworks-dev","description":"Shopware 6 plugin to sync databases from staging/production to local via SSH","archived":false,"fork":false,"pushed_at":"2026-01-28T11:25:29.000Z","size":25,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-29T02:43:19.015Z","etag":null,"topics":["shopware6","shopware6-plugin"],"latest_commit_sha":null,"homepage":"https://www.sidworks.nl","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/sidworks-dev.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,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-28T08:07:25.000Z","updated_at":"2026-01-28T11:24:58.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/sidworks-dev/sw-plugin-database-sync","commit_stats":null,"previous_names":["sidworks-dev/sw-plugin-database-sync"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/sidworks-dev/sw-plugin-database-sync","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidworks-dev%2Fsw-plugin-database-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidworks-dev%2Fsw-plugin-database-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidworks-dev%2Fsw-plugin-database-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidworks-dev%2Fsw-plugin-database-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sidworks-dev","download_url":"https://codeload.github.com/sidworks-dev/sw-plugin-database-sync/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidworks-dev%2Fsw-plugin-database-sync/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29333909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T12:42:24.625Z","status":"ssl_error","status_checked_at":"2026-02-11T12:41:23.344Z","response_time":97,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["shopware6","shopware6-plugin"],"created_at":"2026-01-31T18:00:25.931Z","updated_at":"2026-02-11T14:01:10.166Z","avatar_url":"https://github.com/sidworks-dev.png","language":"PHP","funding_links":[],"categories":["Plugins"],"sub_categories":["Other"],"readme":"# Sidworks Database Sync Plugin\n\nA Shopware 6 plugin for syncing databases from staging/production environments to your local development environment via SSH.\n\n## Features\n\n- Sync from staging or production environments\n- SSH connection support with key authentication\n- Automatic database dump, download, and import\n- Table filtering for performance and GDPR compliance\n- Local environment overrides (URLs, domains, system config)\n- Post-sync console commands (e.g. deactivate plugins, create users)\n- Apply config overrides without a full sync (`--apply-config-only`)\n- DDEV compatible\n\n## Installation\n\n#### Via Composer (Recommended)\n\n```bash\ncomposer require sidworks/sw-plugin-database-sync --dev\nbin/console plugin:refresh\nbin/console plugin:install --activate SidworksDatabaseSync\nbin/console cache:clear\n```\n\n#### Manual Installation\n\n1. Clone or download this repository to `custom/plugins/SidworksDatabaseSync`\n2. Run the following commands:\n\n```bash\nbin/console plugin:refresh\nbin/console plugin:install --activate SidworksDatabaseSync\nbin/console cache:clear\n```\n\n## Configuration\n\n### Environment Variables\n\nAdd the following to your `.env.local` file:\n\n```bash\n# Staging Environment\nSW_DB_SYNC_STAGING_HOST=your-staging-server.com\nSW_DB_SYNC_STAGING_USER=your-username\nSW_DB_SYNC_STAGING_PORT=22\nSW_DB_SYNC_STAGING_PROJECT_PATH=/var/www/html\nSW_DB_SYNC_STAGING_KEY=~/.ssh/id_ed25519   # Optional: SSH key path\n\n# Production Environment\nSW_DB_SYNC_PRODUCTION_HOST=your-production-server.com\nSW_DB_SYNC_PRODUCTION_USER=your-username\nSW_DB_SYNC_PRODUCTION_PORT=22\nSW_DB_SYNC_PRODUCTION_PROJECT_PATH=/var/www/html\nSW_DB_SYNC_PRODUCTION_KEY=~/.ssh/id_ed25519 # Optional: SSH key path\n\n# Local overrides\nSW_DB_SYNC_LOCAL_DOMAIN=your-project.ddev.site\nSW_DB_SYNC_DOMAIN_MAPPINGS=production.com:your-project.ddev.site,staging.com:your-project.ddev.site\nSW_DB_SYNC_CLEAR_CACHE=true   # Set to \"false\" to skip cache clearing\n```\n\n#### Required Variables\n\n| Variable | Description |\n|----------|-------------|\n| `SW_DB_SYNC_[ENV]_HOST` | Hostname or IP address of the server |\n| `SW_DB_SYNC_[ENV]_USER` | SSH username |\n| `SW_DB_SYNC_[ENV]_PORT` | SSH port (default: 22) |\n| `SW_DB_SYNC_[ENV]_PROJECT_PATH` | Remote Shopware project directory path |\n\n#### Optional Variables\n\n| Variable | Description |\n|----------|-------------|\n| `SW_DB_SYNC_[ENV]_KEY` | Path to SSH private key (supports `~/` expansion) |\n| `SW_DB_SYNC_LOCAL_DOMAIN` | Default local domain for URL overrides |\n| `SW_DB_SYNC_DOMAIN_MAPPINGS` | Comma-separated `from:to` domain mappings |\n| `SW_DB_SYNC_CLEAR_CACHE` | Clear cache after sync — `true` (default) or `false` |\n\nReplace `[ENV]` with either `STAGING` or `PRODUCTION`.\n\n## Advanced Configuration (Config File)\n\nCreate a `sw-db-sync-config.json` file in your Shopware root directory:\n\n```bash\ncp vendor/sidworks/sw-plugin-database-sync/sw-db-sync-config.json.example sw-db-sync-config.json\nnano sw-db-sync-config.json\n```\n\nWhen this file exists, it takes priority over environment variable domain mappings.\n\n### Configuration Sections\n\n#### `ignore_tables`\n\nTables to skip during the data dump. The example file includes 62 commonly ignored tables covering:\n\n**Performance tables** (always recommended):\n- `enqueue` — Message queue\n- `product_keyword_dictionary` — Search keywords\n- `product_search_keyword` — Search index\n- `log_entry` — Application logs\n- `message_queue_stats` — Queue statistics\n- `elasticsearch_index_task` — Search indexing\n- `state_machine_history` — Order/payment state history\n\n**GDPR/Privacy tables** (customer and order data):\n- `customer`, `customer_address`, `customer_tag`, `customer_wishlist`\n- `order`, `order_address`, `order_delivery`, `order_line_item`, `order_transaction`\n- `cart` — Shopping carts\n- `user`, `user_config`, `user_recovery`, `user_access_key` — Admin users\n- `newsletter_recipient`, `newsletter_recipient_tag`\n- Payment plugin tables (Klarna, Payone, Pay.nl, Unzer)\n\n**Tip**: Remove tables from the list if you need them in development. For example, keep `user` if you need existing admin accounts.\n\n#### `sales_channel_domains`\n\nMap sales channel IDs to local domains. Find your sales channel IDs with:\n\n```sql\nSELECT LOWER(HEX(id)) as id, name FROM sales_channel;\n```\n\n```json\n{\n    \"sales_channel_domains\": {\n        \"018d5f1e5e7e7f1e8b8d5f1e5e7e7f1e\": \"https://your-project.ddev.site\"\n    }\n}\n```\n\n#### `system_config`\n\nUpdate Shopware system configuration values after import:\n\n```json\n{\n    \"system_config\": {\n        \"core.basicInformation.email\": \"local@example.com\",\n        \"core.mailerSettings.host\": \"localhost\",\n        \"core.mailerSettings.port\": \"1025\"\n    }\n}\n```\n\nValues that don't exist yet are automatically inserted.\n\n#### `sql_updates`\n\nExecute raw SQL statements after import. Use with caution:\n\n```json\n{\n    \"sql_updates\": [\n        \"UPDATE sales_channel_domain SET url = REPLACE(url, 'production.com', 'ddev.site')\"\n    ]\n}\n```\n\n#### `post_sync_commands`\n\nConsole commands to run after the sync completes. Failed commands produce warnings but don't abort the process:\n\n```json\n{\n    \"post_sync_commands\": [\n        \"user:create admin -a --email info@example.com -p thisIsMyPassword\",\n        \"plugin:refresh\",\n        \"plugin:install SidworksDatabaseSync -a\",\n        \"theme:compile\"\n    ]\n}\n```\n\nCommon use cases:\n- Create a local admin user after importing (since `user` table is typically ignored)\n- Deactivate production-only plugins or apps\n- Refresh and reinstall the sync plugin itself after import\n- Recompile themes\n\n### Environment Variables vs Config File\n\n| Method | Use case |\n|--------|----------|\n| Environment variables (`.env.local`) | Simple domain mappings, basic setups |\n| Config file (`sw-db-sync-config.json`) | Advanced overrides, system config, SQL updates, post-sync commands |\n\nIf `sw-db-sync-config.json` exists, it takes priority over environment variable domain mappings.\n\n## Usage\n\n### Basic sync from staging\n\n```bash\nbin/console sidworks:db:sync staging\n```\n\n### Sync from production\n\n```bash\nbin/console sidworks:db:sync production\n```\n\n### Options\n\n| Option | Description |\n|--------|-------------|\n| `--keep-dump, -k` | Keep the dump file in the project root after import |\n| `--skip-import` | Only download the dump, don't import |\n| `--no-gzip` | Don't compress the dump (faster for small databases) |\n| `--skip-overrides` | Skip applying local environment overrides |\n| `--no-ignore` | Dump all tables (don't ignore any) |\n| `--apply-config-only[=path]` | Only apply config file overrides without syncing |\n| `--skip-cache-clear` | Skip clearing cache after applying configuration |\n| `--skip-post-commands` | Skip running post-sync commands |\n\n### Apply config only (no database sync)\n\nRe-apply your `sw-db-sync-config.json` overrides without downloading a new database dump. Useful after manual database changes or when you just need to update system config:\n\n```bash\n# Use default sw-db-sync-config.json\nbin/console sidworks:db:sync --apply-config-only\n\n# Use a custom config file\nbin/console sidworks:db:sync --apply-config-only=custom-config.json\n\n# Use an absolute path\nbin/console sidworks:db:sync --apply-config-only=/path/to/config.json\n\n# Apply config only, skip cache clear and post-sync commands\nbin/console sidworks:db:sync --apply-config-only --skip-cache-clear --skip-post-commands\n```\n\n### Verbose output\n\nShow which tables are being ignored:\n\n```bash\nbin/console sidworks:db:sync staging -v\n```\n\n## DDEV Usage\n\nIf you're using DDEV, forward your SSH agent first:\n\n```bash\nddev auth ssh\n```\n\nThen run the sync command inside the container:\n\n```bash\nddev exec bin/console sidworks:db:sync staging\n```\n\n## How It Works\n\n### Execution Flow\n\n1. **Validate configuration** — Check required SSH and environment settings\n2. **Fetch remote environment** — Read database credentials from the remote server via SSH (supports `.env.local.php`, `.env.local`, and `.env`)\n3. **Create remote dump** — Two-step mysqldump (structure + data) on the remote server\n4. **Download dump** — Transfer the compressed dump via rsync\n5. **Cleanup remote** — Delete the dump file from the remote server\n6. **Import database** — Import dump into local database with optimizations\n7. **Apply overrides** — Update domains, system config, and run SQL updates\n8. **Clear cache** — Run `cache:clear:all`\n9. **Run post-sync commands** — Execute configured console commands\n10. **Cleanup local** — Delete the local dump file (unless `--keep-dump`)\n\n### mysqldump Strategy\n\nThe plugin uses a two-step dump process:\n\n1. **Structure dump**: `--no-data --routines` exports table structures, triggers, stored procedures, and functions\n2. **Data dump**: `--no-create-info --skip-triggers` exports data only, skipping ignored tables\n\n**Common flags:**\n- `--single-transaction` — InnoDB consistent read without table locks (safe for production)\n- `--quick` — Stream results without buffering entire tables\n- `-C` — Compress data between client and server\n- `--hex-blob` — Binary data as hex for portability\n- `--column-statistics=0` — Disable statistics collection (auto-detected if supported)\n\n**Post-processing (both steps):**\n- `LANG=C LC_CTYPE=C LC_ALL=C` — Consistent character encoding\n- `sed` strips `DEFINER` clauses for cross-server compatibility\n\n### Import Optimization\n\nThe import pipeline applies several optimizations:\n\n- `SET FOREIGN_KEY_CHECKS=0` — Disables FK constraint checks during import to prevent deadlocks and speed up loading\n- `SET UNIQUE_CHECKS=0` — Skips unique index verification during bulk insert\n- `SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\"` — Preserves explicit zero values in auto-increment columns\n- DEFINER clauses are stripped locally via `sed` before piping to `mysql`, avoiding privilege errors when views or stored procedures reference specific users\n- Foreign key and unique checks are re-enabled at the end of the import\n\n### Override Priority\n\n1. If `sw-db-sync-config.json` exists → use config file (sales channel domains, system config, SQL updates)\n2. Otherwise → use environment variable domain mappings (`SW_DB_SYNC_DOMAIN_MAPPINGS`)\n3. Fallback → use `SW_DB_SYNC_LOCAL_DOMAIN` to set all sales channel domains\n\n## Troubleshooting\n\n### SSH Connection Failed\n\n1. **In DDEV**: Run `ddev auth ssh` to forward your SSH agent into the container\n2. **SSH Key**: Set `SW_DB_SYNC_[ENV]_KEY` to your private key path\n3. **SSH Agent**: Ensure your key is loaded: `ssh-add ~/.ssh/your_key`\n\n### Permission Denied\n\nYour SSH user needs:\n- Read access to the remote `.env` file\n- Execute permissions for `mysqldump`\n- Write permissions to the remote project directory (for temporary dump file)\n\n### Remote .env Not Found\n\nVerify that `SW_DB_SYNC_[ENV]_PROJECT_PATH` points to the Shopware root directory containing the `.env` file.\n\nThe plugin reads remote environment files in this priority order:\n\n1. **`.env.local.php`** — Cached PHP array (takes full precedence if exists)\n2. **`.env.local`** — Local overrides (merged on top of `.env`)\n3. **`.env`** — Base environment file\n\nThis matches Symfony's environment loading behavior.\n\n### Import Fails with DEFINER Errors\n\nThis is handled automatically. Both the remote dump and local import pipeline strip DEFINER clauses. If you still encounter errors, check that your MySQL user has `SUPER` or `PROXY` privileges, or verify the dump file isn't corrupted.\n\n## Requirements\n\n- Shopware 6.6+ \u0026 6.7+\n- PHP 8.1+\n- SSH access to remote servers\n- `mysqldump` on the remote server\n- `rsync` for file transfer\n- `gzip` / `gunzip` (unless using `--no-gzip`)\n\n## Author\n\nSidworks — https://www.sidworks.nl/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidworks-dev%2Fsw-plugin-database-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsidworks-dev%2Fsw-plugin-database-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidworks-dev%2Fsw-plugin-database-sync/lists"}