/tsh-stack-mysql:migrating-mysql-schemasfrom TSH Stack: MySQL
Writes and reviews MySQL/Aurora MySQL schema changes on populated InnoDB tables: ALTER TABLE algorithms (INSTANT, INPLACE, COPY), metadata locks, replica lag, gh-ost/pt-online-schema-change, and batched backfills. Use when adding, changing, or dropping columns, indexes, or constraints on production tables.
Ships in TSH Stack: MySQL. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A migration that is correct SQL can still take production down. On MySQL three things
decide it: the metadata lock every ALTER TABLE waits for, whether the statement
copies the table while blocking writes, and how long replicas take to replay it.
This skill makes all three explicit before a migration ships.
MySQL 8.0, 8.4 LTS and 9.7 LTS with InnoDB, including Amazon Aurora MySQL 3
(8.0-compatible) and Aurora MySQL 8.4 (treat as 8.4). Community 8.0 reached end of
life in April 2026; Aurora MySQL 3 has standard support to April 2028. Run SELECT VERSION(); (on Aurora also
SELECT AURORA_VERSION();) before choosing a recipe: several need an 8.0 minor,
marked 8.0.29+ in the references, and 8.0.29 itself was withdrawn for an
instant-DDL defect. An innovation release (9.0 to 9.6) is short-lived: say so,
and check each version-marked behaviour against that release's notes rather than
assuming 8.4 or 9.7. Below 8.0, stop and say the version is unsupported; continue only
when asked.
MySQL only. If the database is MariaDB, PostgreSQL, SQL Server or another engine, say this skill does not apply and stop: online DDL, its algorithms and their limits differ by engine, and MariaDB's have diverged from MySQL's. When a skill for that engine is available in this session, load it instead; name none that is absent. On PlanetScale or Vitess, the platform's own schema-change workflow replaces the migration recipes here.
Read the project's migration tool and its conventions first: where migrations live, how they run in CI and at deploy, and whether an online schema change tool (gh-ost, pt-online-schema-change) is already installed and approved. The ORM or framework skill installed for the project owns the tool's mechanics; this skill owns what the SQL does to a live database. A project rule (for example "every migration is reviewed by the DBA") outranks this skill.
This skill does not provision databases, tune server parameters, or run migrations against a shared or production environment.
| Severity | Rule |
|---|---|
| MUST | Name, for every statement, the algorithm it uses (INSTANT, INPLACE, COPY), whether it rebuilds the table and whether it permits concurrent writes, from online-ddl-and-locks.md, before calling a migration safe. |
| MUST | State ALGORITHM and LOCK on every ALTER TABLE against a populated table (ALGORITHM=INSTANT alone, since INSTANT rejects any LOCK but DEFAULT; or ALGORITHM=INPLACE, LOCK=NONE). Without them MySQL silently falls back to a table copy that blocks writes; with them it refuses. |
| MUST | Run SET SESSION lock_wait_timeout to a few seconds before any DDL on a table with traffic. The default is a year; every ALTER, even an instant one, waits for an exclusive metadata lock on the table (and, for a foreign key, on the referenced table too), at the start and again at the end, and every query on the table queues behind it while it waits. |
| MUST | Treat an operation that needs ALGORITHM=COPY (a column type change, adding a CHECK constraint or a stored generated column, most character set changes on an indexed column) on a large table with traffic as work for an online schema change tool or an agreed maintenance window (there, with ALGORITHM=COPY written out), never a plain migration. Before a tool run, show with pre-check queries that existing rows already satisfy the new definition: both tools copy with INSERT IGNORE, which turns a NULL into 0, truncates, or drops a violating row without failing. |
| MUST | Account for binlog replicas before any DDL: a replica starts the same ALTER only after the source commits it and lags for its whole duration, and its applier waits for the metadata lock behind the replica's own long transactions with the replica's global lock_wait_timeout, since the session value is not replicated. Check the replicas for open transactions first; throttle with an online schema change tool when lag matters. |
| MUST | Put one DDL statement in each migration. MySQL commits implicitly after every DDL statement, so no tool can roll back a half-applied migration. |
| MUST | Check for orphan rows before adding a foreign key in place with foreign_key_checks=0, and set it for that session only: in that mode MySQL does not validate existing rows. |
| MUST | Rename or retype a column used by running code through expand-and-contract across deploys, and ship the code that stops reading a column before the migration that drops it. |
| MUST | Backfill large tables in bounded batches outside the schema migration, never one UPDATE over the whole table. |
| MUST | When the migration is written with an ORM or framework that has its own skill available in this session (a Symfony, NestJS or Python stack skill, for example), load that skill too, before writing the migration file. This skill owns what the SQL does to the database; that one owns how the tool writes and runs it. Name none that is absent. |
| MUST | When asked to review a whole change or its merge readiness (a pull request or a diff that also changes application code), not only the migration, load the general code-review skill too when one is available in this session (reviewing-code, for example). This skill covers the migration; that one covers the rest of the change. Name none that is absent. |
| NEVER | Run a migration against production, staging or any shared database yourself. Hand over the SQL, the tool command and the order of steps. |
| NEVER | Let a deploy retry a failed migration automatically, with one exception: a one-statement migration that failed with ERROR 1205 (lock wait timeout) applied nothing and may be retried a few times with a pause. Any other failure can leave the schema and the tool's record of it disagreeing. |
| NEVER | Call a migration safe on a table whose size, traffic and replica topology you do not know. Ask, or state the assumption in the review. |
| Reference | Load when | Covers |
|---|---|---|
| Online DDL and locks | Any migration on a table with data, every time | Algorithms and what each operation supports, the metadata lock queue, lock_wait_timeout, replica lag, finding blockers |
| Zero-downtime recipes | Adding an index or constraint, renaming, retyping or dropping a column | Step-by-step recipes, version differences, what has no online path |
| Online schema change tools | An operation needs COPY, or an in-place build would lag replicas too long | gh-ost and pt-online-schema-change: requirements, foreign keys, throttling, cut-over, Aurora and RDS |
| Backfilling data | Rows must be updated or copied as part of the change | Batching by primary key, locks, undo history, replica lag, resumability |
| Migration tools | The migration is written with an ORM or migration runner | Implicit commits per tool, adding ALGORITHM and LOCK, recording out-of-band changes, what generators emit |
Read online-ddl-and-locks.md before judging any migration, and zero-downtime-recipes.md before writing one that touches an existing column.
information_schema.TABLES, an estimate), its write rate, the replica topology
(binlog replicas lag, Aurora replicas share storage), whether long transactions
are normal there, and which online schema change tool is available. If you cannot
read them, ask; a 1,000-row table and a 200-million-row table need different
migrations.lock_wait_timeout, ALGORITHM and LOCK to every statement that runs
natively, with migration-tools.md for how the
tool carries them.For each statement: the algorithm and lock it gets, the risk on this table, and the safe replacement. Lead with anything that copies the table or blocks writes on a table with traffic, then anything that will lag replicas. Say plainly when the migration is safe as written.
What SKILL.md sets; muted values are Claude Code's defaults
Trigger on: an ALTER TABLE on a large MySQL table, adding an index, foreign key, CHECK or NOT NULL to an existing MySQL table, widening an INT key to BIGINT, renaming or dropping a column in MySQL, a migration stuck on 'Waiting for table metadata lock', an ALTER that froze writes or left replicas behind, choosing between native online DDL, gh-ost and pt-online-schema-change, 'There is no active transaction' from Doctrine, or reviewing a Laravel, Doctrine, TypeORM, Prisma, Rails, Django, Alembic, Knex, Flyway or Liquibase migration that targets MySQL. Table design is designing-mysql-schemas; a slow query is optimizing-mysql-queries.
3 skills in this plugin
/designing-mysql-schemasMySQL and InnoDB table design beneath any ORM: strict sql_mode, utf8mb4 and the collation that decides which strings a unique key treats as duplicates, DATETIME in UTC instead of TIMESTAMP and its 2038 limit, DECIMAL money, BIGINT AUTO_INCREMENT or BINARY(16) UUID keys, ENUM against lookup tables, JSON with generated columns, foreign keys whose cascades the 8.x binlog never records, CHECK constraints that only a CREATE TABLE adds cheaply, and tenant isolation without row-level security. Use when creating MySQL tables for a new feature, reviewing an entity or schema for a MySQL or Aurora MySQL database, or deciding how to store a kind of data there./optimizing-mysql-queriesDiagnoses slow MySQL and Aurora MySQL queries from evidence: performance_schema statement digests, sys views and the slow query log ranked by total time and rows examined, EXPLAIN access types, key_len and Extra notes such as Using filesort and Using temporary, EXPLAIN ANALYZE actual rows per loop, InnoDB index statistics and histograms, indexes chosen around the clustered primary key, and the query shapes MySQL cannot index: OFFSET pages, keyset conditions written as row constructors, DATE() on a DATETIME, a VARCHAR compared with a number, joins across utf8mb3 and utf8mb4. Use when an endpoint, report or job is slow because of a MySQL query, or someone proposes FORCE INDEX or a new index.npx claudepluginhub thesoftwarehouse/agentic-collections --plugin tsh-stack-mysqlOther plugins' skills for the same job