mysql-database
Designs and implements MySQL schemas for Laravel 12 using migrations, Eloquent relationships, factories, seeders, constraints, indexes, transactions, and query optimization. Use for persistence and da
Files2
View on GitHubSKILL.md.agents/skills/mysql-database/SKILL.md
GitHubMySQL Database Engineering
Role
Act as a senior Laravel + MySQL database engineer.
Workflow
- Inspect current migrations, models, factories, seeders, and query patterns.
- Identify entities and cardinality.
- Define ownership and lifecycle.
- Choose column types and nullability deliberately.
- Add constraints and indexes based on actual access patterns.
- Implement migration.
- Update models/relationships/casts.
- Update factories/seeders when relevant.
- Add tests.
- Review query performance.
Migration rules
- Migrations are version control for schema.
- Do not rewrite old migrations that may have run in shared environments; create a new migration.
- Keep
upanddowncoherent where practical. - Use foreign keys for referential integrity.
- Define nullability/defaults intentionally.
- Never drop/rename production data structures without explicit approval and a rollout plan.
MySQL design
- Use appropriate numeric/string/date/json types.
- Prefer
foreignIdconventions where compatible with the existing schema. - Add unique constraints where the business rule requires uniqueness.
- Index columns based on real filtering/join/order patterns.
- Avoid indexing every column.
- Consider composite indexes for common multi-column queries.
Eloquent relationships
Use the correct relationship type:
- belongsTo
- hasOne
- hasMany
- belongsToMany
- polymorphic relationships only when genuinely needed
Performance
Check for:
- N+1 queries
- SELECT * on large records
- unbounded queries
- missing indexes
- excessive eager loading
- expensive LIKE patterns
- inefficient OFFSET pagination
Prefer eager loading, pagination/cursor pagination, aggregates, scopes, and targeted selects when appropriate.
Integrity
Application validation is not a replacement for database constraints. Use unique keys, foreign keys, nullability, and other supported constraints where appropriate.
Factories/seeders
Factories should produce valid realistic data. Seeders should be safe for local/dev use and must not contain secrets or production-sensitive data.