agentleFS
mohitkalemohitkale/wordpress-devkit/skills/db-migration/SKILL.md

db-migration

Skill1 starsChanged 4 months agoMITView on GitHub

Generate safe wp-cli search-replace commands for a WordPress URL migration. Use this when the user is moving a site between environments (staging to production, old domain to new domain), changing the site URL, or needs to rewrite URLs in the database. Produces a dry-run command first and a clear warning about serialized data.

26 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use api-endpoint, write-tests and 7 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • tadoEngSkill

    api-endpoint

    Add or change a backend API endpoint on this product, keeping Pydantic as the single contract authority and regenerating the TypeScript client. Use when asked to add an endpoint, expose data to the frontend, change a request or response shape, or wire a new backend capability into a page.

    Also in 4 projects that use this

  • SentrySkill

    write-tests

    Write tests following project conventions. Use when adding new tests or modifying existing ones.

    Also in 3 projects that use this

  • Microsoft AzureSkill

    git-workflow

    Squad branching model: dev-first workflow with insiders preview channel

    Also in 3 projects that use this

  • Microsoft AzureSkill

    design

    Design rules and conventions for the API Center Portal. Use when editing detail pages, card components, badges, layout, navigation, sidebars, or headers. Covers badge styling, metadata placement, page navigation patterns, and layout alignment.

    Also in 3 projects that use this

  • AnthropicSkill

    debug

    Structured debugging session — reproduce, isolate, diagnose, and fix. Trigger with an error message or stack trace, "this works in staging but not prod", "something broke after the deploy", or when behavior diverges from expected and the cause isn't obvious.

    Also in 3 projects that use this

  • VercelSkill

    agent-browser

    Automates browser interactions for web testing, form filling, screenshots, and data extraction. Use when the user needs to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.

    Also in 3 projects that use this

  • +1 more from Azure

The file

We split this skill into the rules it gives an agent

10 rules. 0 are common, 4 are distinctive, and 6 are very specific to this project.

  • 0

    Common

    Most of the 22 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If either URL is missing, ask for both.

    line 18
  2. Distinctive:

    Always run a backup first.

    line 32
  3. Very specific:

    If the site is very large, use --add-drop-table and compress:

    line 38
  4. Distinctive:

    Read the output. The last line reports the number of replacements across each table.

    line 65
  5. Very specific:

    If the site is a WordPress multisite, add --network and run per-site for any per-site tables:

    line 98
  6. Distinctive:

    Do not run any migration command from this skill.

    line 159
  7. Very specific:

    Do not use raw SQL like UPDATE wp_options SET option_value = REPLACE(option_value, 'old', 'new') anywhere.

    line 160
  8. Very specific:

    Do not rewrite the guid column.

    line 161
  9. Distinctive:

    Do not skip the backup step, even on staging.

    line 162
  10. Very specific:

    Do not print database credentials, even if they appear in wp-config.php.

    line 163

“Common” is measured: kept by at least 6 in 10 of the 22 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Generate safe wp-cli search-replace commands

Produce the exact wp-cli commands the user should run to migrate URLs in a WordPress database. Always generate a dry-run first, a backup step, and then the real run. Serialized data is handled correctly by wp search-replace because it reserializes after replacement, so the tool must be used, not raw SQL.

Inputs

$ARGUMENTS is two URLs: the old URL and the new URL.

Example: https://staging.acme.com https://acme.com.

If either URL is missing, ask for both. Confirm whether the source has http:// or https:// and whether the target has a trailing slash convention (WordPress stores it without trailing slash).

Workflow

  1. Confirm the environment. Ask which environment the commands will run against (staging, production, local). The commands should never be run on production without a confirmed backup.
  2. Normalize both URLs: strip trailing slashes, confirm the scheme (http vs https).
  3. Output the four-step plan: backup, dry-run, real run, flush caches. Keep it in the conversation for the user to review before running.
  4. Print the serialized-data warning in plain language.
  5. Remind the user to clear caches and rebuild permalinks after the real run.

The four commands

Step 1. Take a backup

Always run a backup first. The wp-cli export is portable and keeps the site recoverable.

wp db export pre-migration-$(date +%Y%m%d-%H%M%S).sql

If the site is very large, use --add-drop-table and compress:

wp db export pre-migration-$(date +%Y%m%d-%H%M%S).sql --add-drop-table
gzip pre-migration-*.sql

Step 2. Dry-run the search-replace

Dry-run prints what would change without modifying anything. Always run this first.

wp search-replace 'https://staging.acme.com' 'https://acme.com' \
  --all-tables-with-prefix \
  --precise \
  --recurse-objects \
  --skip-columns=guid \
  --dry-run

Flag meanings:

  • --all-tables-with-prefix: replace in every table that starts with the current table prefix, not just core.
  • --precise: use PHP-side serialized-safe replacement. Slower but correct for every case.
  • --recurse-objects: walk into serialized PHP objects, not just arrays.
  • --skip-columns=guid: never rewrite the guid column. The GUID is a stable identifier for feed readers, not a URL.
  • --dry-run: print changes, do not apply.

Read the output. The last line reports the number of replacements across each table. If the counts look reasonable, continue.

Step 3. Run it for real

Remove --dry-run:

wp search-replace 'https://staging.acme.com' 'https://acme.com' \
  --all-tables-with-prefix \
  --precise \
  --recurse-objects \
  --skip-columns=guid

Step 4. Post-migration tasks

wp cache flush
wp rewrite flush

wp cache flush clears whatever object cache is active, whether the built-in, Redis, or Memcached. If the site also uses a page cache plugin (WP Super Cache, W3 Total Cache, LiteSpeed Cache), clear that from its admin page.

The serialized-data warning

This warning is important. Announce it before the user runs anything.

Warning. WordPress stores many values as serialized PHP arrays or objects. A serialized string contains byte-length prefixes like s:24:"https://staging.acme.com". A raw SQL statement like UPDATE wp_options SET option_value = REPLACE(option_value, 'https://staging.acme.com', 'https://acme.com') will replace the URL but not update the s:24 length prefix, corrupting the serialized data. This breaks theme mods, widgets, plugin settings, and custom fields in ways that are hard to diagnose.

Always use wp search-replace. It deserializes, replaces, and reserializes with correct length prefixes. Never run raw SQL to rewrite URLs.

Multisite

If the site is a WordPress multisite, add --network and run per-site for any per-site tables:

wp search-replace 'https://staging.acme.com' 'https://acme.com' \
  --network \
  --all-tables-with-prefix \
  --precise \
  --recurse-objects \
  --skip-columns=guid \
  --dry-run

Also update DOMAIN_CURRENT_SITE in wp-config.php if the primary site URL changed.

Output format

Present a single copyable migration-plan.sh example in the conversation, with the three commands and the post-migration tasks commented by step. Do not create files. Example content:

#!/usr/bin/env bash
set -euo pipefail

# Step 1: backup
wp db export "pre-migration-$(date +%Y%m%d-%H%M%S).sql" --add-drop-table

# Step 2: dry-run
wp search-replace 'https://staging.acme.com' 'https://acme.com' \
  --all-tables-with-prefix \
  --precise \
  --recurse-objects \
  --skip-columns=guid \
  --dry-run

echo "Review the dry-run output above. Re-run this script without the --dry-run line to apply."

# Step 3: real run (comment out until dry-run has been reviewed)
# wp search-replace 'https://staging.acme.com' 'https://acme.com' \
#   --all-tables-with-prefix \
#   --precise \
#   --recurse-objects \
#   --skip-columns=guid

# Step 4: flush caches
# wp cache flush
# wp rewrite flush

Tell the user to review the plan before running, and to uncomment step 3 only after step 2 has been checked.

Example

User runs /wordpress-devkit:db-migration https://staging.acme.com https://acme.com.

The skill:

  1. Asks which environment the commands will run against.
  2. Presents a migration-plan.sh example with the four steps above.
  3. Prints the serialized-data warning.
  4. Reminds the user to take the backup first and to review the dry-run output before the real run.

Do not

  • Do not run any migration command from this skill. Generate commands only. The user runs them.
  • Do not use raw SQL like UPDATE wp_options SET option_value = REPLACE(option_value, 'old', 'new') anywhere. It corrupts serialized data.
  • Do not rewrite the guid column. Always include --skip-columns=guid.
  • Do not skip the backup step, even on staging. Backups are free insurance.
  • Do not print database credentials, even if they appear in wp-config.php.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.