migrations
Skill4 starsChanged 5 months agoMITView on GitHub
Evolve the database schema with Yii2 migration classes — generate a migration, implement reversible safeUp and safeDown, and apply migrations through the console. Use when the user needs to apply or revert Yii2 migrations through the yii migrate console command; the user wants to create a Yii2 migration class to change the database schema; the user is implementing a Yii2 migration safeUp and safeDown so the schema change can be rolled back. Keywords: yii2, migrations, migration, schema, safeup, safedown, php74.
8 other projects use a version of this.
Adopted by
Most recently taken up by
- kuldeeps48/agentic-engineeringtheir own version, first seen Nov 16, 2026
- theopenco/llmgatewaytheir own version, first seen Nov 15, 2026
- butterbase-ai/butterbase-plugintheir own version, first seen Oct 8, 2026
- orangehrm/orangehrmtheir own version, first seen Oct 8, 2026
- dotnet/efcoretheir own version, first seen Oct 8, 2026
- nahid-sparktales/agent-dispatchertheir own version, first seen Sep 21, 2026
Used with
Projects with it also use schema-design.
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.
HamzaSheikh768Skillschema-design
Designs normalized, performant, and future-proof PostgreSQL database schemas with proper normalization, indexing strategy, constraints, partitioning considerations, and scalability planning.
Also in 3 projects that use this
Other versions8 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 8
- dotnet/efcore★ 15ksame name
- theopenco/llmgateway★ 1.7ksame name
- orangehrm/orangehrm★ 1.1ksame name
- butterbase-ai/butterbase-plugin★ 535same name
- butterbase-ai/butterbase-skills★ 535same name
- nahid-sparktales/agent-dispatcher★ 59same name
- hallucinaut/skills★ 0same name
- kuldeeps48/agentic-engineering★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository119 other files it gives its agents.
- strategy-bitrix-d7-incrementalSkill
- strategy-explicit-over-magicSkill
- strategy-framework-conventionsSkill
- strategy-legacy-safe-editsSkill
- strategy-minimal-diffSkill
- strategy-no-untested-refactorSkill
- strategy-preserve-public-apiSkill
- strategy-readonly-immutabilitySkill
- strategy-security-firstSkill
- strategy-test-drivenSkill
- openapiSkill
- paginationSkill
- rest-designSkill
- versioningSkill
- cqrsSkill
- dependency-inversionSkill
- hexagonalSkill
- repository-patternSkill
- service-layerSkill
- bitrixSkill
- findings-reportSkill
- laravelSkill
- performanceSkill
- phpSkill
- project-analysisSkill
- refactoringSkill
- roi-prioritizationSkill
- securitySkill
- stack-detectionSkill
- cache-layersSkill
- component-engineSkill
- d7-eventsSkill
- d7-loaderSkill
- d7-orm-queriesSkill
- iblock-elementsSkill
- kernel-main-moduleSkill
- localizationSkill
- controllersSkill
- ormSkill
- validationSkill
- controllersSkill
- query-builderSkill
- routingSkill
- autoload-psr4Skill
- dependency-managementSkill
- scriptsSkill
- connection-poolingSkill
- mysql-indexingSkill
- redisSkill
- transactionsSkill
- ci-github-actionsSkill
- deployment-strategiesSkill
- docker-phpSkill
- env-configSkill
- associationsSkill
- entities-mappingSkill
- orm-basicsSkill
- entity-apiSkill
- module-developmentSkill
- routing-controllersSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
5 rules. 0 are common, 3 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 5 edited versions we read keep these.
3
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 63
Do not run ad hoc ALTER TABLE statements directly against a shared database instead of writing a migration.
- Distinctive: line 64
Do not use migrations to load large volumes of application data that belongs in a seeder or fixture.
- Very specific: line 72
Run yii migrate/create create_order_table to generate a timestamped migration class skeleton.
- Very specific: line 74
Run yii migrate/up, then confirm yii migrate/down 1 reverts the change without errors.
- Distinctive: line 105
Not applicable — no I/O, auth, or untrusted input.
“Common” is measured: kept by at least 6 in 10 of the 5 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.
Files
<!-- generated: do not edit — source: knowledge/atoms/yii2/migrations/ --><!-- schema: atomVersion=3 skillVersion=2 graphVersion=1 --><!-- compile: @php-skills/compiler v1.0.0 (deterministic build) -->Yii2 Database Migrations
When to use
- The user needs to apply or revert Yii2 migrations through the yii migrate console command.
- The user wants to create a Yii2 migration class to change the database schema.
- The user is implementing a Yii2 migration safeUp and safeDown so the schema change can be rolled back.
When NOT to use
- Do not run ad hoc ALTER TABLE statements directly against a shared database instead of writing a migration.
- Do not use migrations to load large volumes of application data that belongs in a seeder or fixture.
Core guidance
- Prefer safeUp/safeDown over up/down — Implement
safeUp()andsafeDown()rather thanup()/down()so each migration runs inside a transaction on databases that support transactional DDL.
Quick recipe
- Run
yii migrate/create create_order_tableto generate a timestamped migration class skeleton. (verify: A new migration file appears in the migrations directory.) - Build the table in
safeUp()with the schema builder and drop it insafeDown()so the change is reversible. (verify: safeDown() cleanly removes everything safeUp() created.) - Run
yii migrate/up, then confirmyii migrate/down 1reverts the change without errors. (verify: The schema returns to its prior state after down.)
Best practices
- Give foreign keys and indexes explicit, stable names in
addForeignKey()/createIndex()sosafeDown()can drop them by the same name - Scope each migration to a single logical schema change and use a descriptive generated name (
create_order_table) rather than batching unrelated changes - For each change in
safeUp(), implement its inverse insafeDown(); if a change genuinely cannot be reversed, returnfalsefromsafeDown()to state that explicitly - Define columns with the schema builder (
$this->string(),$this->integer()->notNull()) instead of raw SQL type strings so the migration works across database drivers
Anti-patterns
| Anti-pattern | Why it fails | Do instead |
| Bundling unrelated schema changes in one migration | A monolithic migration cannot be rolled back partially and is hard to review or cherry-pick. | Split each logical change into its own focused, independently reversible migration. |
| Calling Active Record models inside migrations | Models evolve over time, so an old migration that references a later model shape breaks when re-run on a fresh database. | Manipulate data with direct $this->update()/$this->insert() schema commands that stay stable over time. |
| Hard-coding driver-specific SQL DDL | Driver-specific SQL breaks the moment the migration runs against a different database engine. | Use the portable schema builder methods and pass engine options through table options instead. |
See references/anti-patterns.md.
Common mistakes
- Editing an already-applied migration — Changing a migration file after it has been applied in some environments causes schema drift between them. Fix: Never edit an applied migration; write a new migration for the additional change.
- Rollback fails because safeDown was not implemented — Running
yii migrate/downerrors or does nothing becausesafeDown()is empty or missing. Fix: Implement the inverse operations insafeDown(), or returnfalseto declare the migration irreversible. - up() leaves a half-applied schema on failure — A migration using
up()that fails midway leaves some statements applied and others not. Fix: UsesafeUp()/safeDown()so the change runs transactionally and rolls back atomically on error.
Version notes
- safeUp transactions depend on the database engine (PHP >=7.4) — safeUp/safeDown wrap changes in a transaction only where the database supports transactional DDL; MySQL/MariaDB auto-commit most DDL, so a failed multi-statement migration there may not fully roll back.
Security
- Not applicable — no I/O, auth, or untrusted input.
Testing
- Activation and decision behavior are verified in
eval/scenarios/yii2/migrations.yaml.
Additional resources
- references/anti-patterns.md
- references/core.md
- references/examples.md
- references/pitfalls.md
- references/recipes.md
- references/version-differences.md
Knowledge graph
Related: yii2/structure-basics
<!-- graph-fragment: graph/fragments/yii2/migrations.yaml -->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
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.

