/tsh-stack-mysql:designing-mysql-schemasfrom TSH Stack: MySQL
Guides MySQL/InnoDB table design decisions: strict sql_mode, utf8mb4 collation, DATETIME vs TIMESTAMP, DECIMAL for money, UUID vs AUTO_INCREMENT keys, ENUM vs lookup tables, JSON with generated columns, foreign keys, CHECK constraints, and tenant isolation. Use when creating or reviewing MySQL 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.
The schema is the one place a rule holds for every writer: every service, script,
migration and console session. Constraints the database enforces cannot be forgotten
by a code path; rules kept only in application code eventually are. On MySQL two
settings decide whether the schema's rules hold at all: strict sql_mode and the
collation.
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. Some features need an 8.0 minor: CHECK constraints
are enforced from 8.0.16 (parsed and ignored before), expression defaults and
functional indexes from 8.0.13, multi-valued JSON indexes from 8.0.17. Check
SELECT VERSION(); and every environment that runs the schema, including local and
CI. 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: types, collations, constraints and their defaults 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.
Read the existing schema and its conventions first: naming, key type, timestamp columns, character set and collation, how tenancy and deletion are already handled. A convention the project already follows outranks this skill's defaults; a second convention beside the first is a finding, not an improvement. When the schema is generated from an ORM's entities, the ORM's own skill owns how to express a choice in that ORM; this skill owns what the resulting table should be.
This skill does not ship the change. A table that already holds data changes through
migrating-mysql-schemas.
| Severity | Rule |
|---|---|
| MUST | Confirm sql_mode includes STRICT_TRANS_TABLES (or STRICT_ALL_TABLES) in every environment. Without it MySQL truncates and coerces invalid values with a warning instead of rejecting them, and types and ENUMs stop protecting anything. |
| MUST | Use utf8mb4 for text, never utf8 or utf8mb3, and choose each text column's collation deliberately: the default utf8mb4_0900_ai_ci treats Anna, anna and ánna as equal, in unique keys too. |
| MUST | Give every table an explicit primary key; prefer BIGINT (UNSIGNED if the project does) AUTO_INCREMENT or a time-ordered UUID stored as BINARY(16). |
| MUST | Make a column NOT NULL unless absence is a real, distinct state of the data. |
| MUST | Store points in time as DATETIME(3) or DATETIME(6) in UTC, not TIMESTAMP, whose range ends in January 2038. DATETIME stores the session's wall-clock value, so set the server's default time_zone to +00:00 (the parameter group on RDS and Aurora), not only the application connection's. |
| MUST | Store money as DECIMAL with an explicit scale, or as a BIGINT count of the smallest unit, with the currency stored beside it. Never FLOAT or DOUBLE. |
| MUST | Declare a foreign key for every reference to another table's row, choose its ON DELETE deliberately, and give both columns identical types and signedness. |
| MUST | Enforce invariants that must hold for every row with constraints (CHECK, UNIQUE, foreign keys), not only in application validation. |
| 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 schema, load the general code-review skill too when one is available in this session (reviewing-code, for example). This skill covers the schema; that one covers the rest of the change. Name none that is absent. |
| NEVER | Store several values in one delimited text column, or a reference in a column with no foreign key because "it could point at several tables". |
| NEVER | Reach for JSON for attributes that are queried, joined, constrained or present on every row. Those are columns. |
| NEVER | Introduce a second naming, key, timestamp or collation convention into a schema that already has one. |
| Reference | Load when | Covers |
|---|---|---|
| Data types | Choosing a column type, primary key, character set or collation | Text, character sets and collations, numbers and money, time, keys (AUTO_INCREMENT, UUIDs), booleans and status values, JSON, generated columns |
| Keys and constraints | Adding a reference, a uniqueness rule or any invariant | Foreign keys and ON DELETE, CHECK and its limits, unique keys and NULL, uniqueness on some rows only, sql_mode, naming |
| Schema patterns | Deletion, tenancy, history, concurrency, flexible attributes or table size is part of the design | Soft delete versus archive, multi-tenancy without RLS, audit columns, optimistic locking, status history, polymorphic relations, partitioning |
Read data-types.md before choosing a primary key or a collation: they are the hardest choices to change later.
sql_mode and the
server, schema and table default collations.NOT NULL, a key or a
constraint, from keys-and-constraints.md.SHOW CREATE TABLE: an ORM default (nullable columns,
VARCHAR(255) everywhere, TIMESTAMP, utf8mb3, a collation that differs from
the joined table's) is a finding like any other.optimizing-mysql-queries.List each finding with the table and column, the invariant or risk, and the corrected DDL. Lead with what lets bad data in (non-strict mode, a missing constraint or key, a lossy type, a collation that merges values that must differ), then what will be expensive to change later (key type, collation, tenancy, deletion model), then naming and style. Say plainly when the schema is sound.
What SKILL.md sets; muted values are Claude Code's defaults
Trigger on: sketching MySQL tables for a feature, picking a column type, character set, collation or primary key, 'Anna' and 'anna' colliding in a unique key, emoji rejected by a utf8 column, TIMESTAMP versus DATETIME, extending an ENUM, where tenant_id goes, one live row per customer alongside soft-deleted ones, partitioning a MySQL table, or auditing a Doctrine, Eloquent, TypeORM or Prisma model that targets MySQL for integrity gaps. Altering a populated table is migrating-mysql-schemas; a slow query is optimizing-mysql-queries.
Three short reads, in order
mysql-schema, innodb, table-design, database-schema, aurora-mysql
npx claudepluginhub thesoftwarehouse/agentic-collections --plugin tsh-stack-mysql3 skills in this plugin
/migrating-mysql-schemasWrites and reviews MySQL and Aurora MySQL schema changes on populated InnoDB tables: which ALTER TABLE operations run INSTANT, INPLACE or COPY, ALGORITHM and LOCK=NONE clauses that make MySQL refuse a write-blocking table copy, the metadata lock an ALTER waits for while every query queues behind it, lock_wait_timeout, binlog replica lag from long DDL, gh-ost or pt-online-schema-change for what MySQL cannot change online, foreign keys added with foreign_key_checks off, non-transactional DDL in migration tools, and batched backfills. Use when a MySQL migration adds, changes or drops a column, index or constraint on a table with production data, or when reviewing one an ORM generated./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.Other plugins' skills for the same job