migrating-motoko-actors
Motoko actor state migration and schema evolution using the mops-managed migration chain (a migrations/ directory of timestamped files). Use when upgrading…
от jiayaoqijia★ 81 звезда на GitHub
Установить migrating-motoko-actors в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Motoko Actor Migrations
Expert guidance for migrating actor state across canister upgrades with orthogonal persistence.
Critical: Never use classical persistence or pre/post upgrade
Do not use classical (legacy) persistence or system func preupgrade / system func postupgrade. They are error-prone, can leave canisters stuck if they trap, and do not scale.
Also do not use the legacy (with migration = ...) actor-attached syntax. This skill covers mops-managed migrations. When a change requires an explicit migration, write it as a timestamped file in src/backend/migrations/; the chain replays automatically.
How stable state is initialized
Stable actor fields have no initializers in the actor body. The chain in src/backend/migrations/ is what gives them values: the runtime walks it in lexicographic order, running every file on a fresh install and only the files not yet applied to the canister on an upgrade.
When to Use This Skill
- Planning or implementing a canister upgrade that changes actor state
- Deciding between implicit vs explicit migration
- Writing or refactoring a migration function
- Introducing stable state for the first time (a migration with
OldActor = {}, or fold it into the pending migration if there is one)
Migration Folder Rules
- All migrations live in
src/backend/migrations/. The full chain replays in lexicographic filename order on fresh install; on upgrade, only entries newer than the deployed tail run. (The directory is declared aschain = ...under[canisters.<name>.migrations]inmops.toml; an imported project using a non-default canister name may place it elsewhere — readmops.tomlrather than assuming.) - At most one pending migration per build (
check-limit = 1inmops.toml). If a migration is already pending (not yet applied), edit that file to fold in further changes instead of adding another.mops checkcompares the deployed.mostbaseline and names the latest pending file to fold into when the limit is exceeded. If more than one is pending, merge them into one file that keeps the newest filename. Where a hosting platform owns the migrations section andcheck-limit, never edit them to clear an error. - Name new files with just the UTC timestamp, no suffix:
YYYYMMDD_HHMMSS.mo. The timestamp must sort after every existing file. Do NOT encode the change in the name (noAddPriority,AddTags,Init, …) — any feature-ish name tempts you to add another file for the next change instead of editing the one pending file. - Never modify, delete, or rename a migration that was already applied. Applied migrations are tracked by module name, so a rename makes the runtime treat the file as never applied, and an edit to an already-applied file never executes. Some platforms enforce this by making applied migrations read-only, in which case writes to them simply fail. A migration that was not applied yet is pending: edit it rather than add a second migration for the same change.
- Migrations must be self-contained. Inline BOTH old types AND new types in the migration file. Only
mo:core/...and mops package imports are allowed — never../typesor any project module. The chain replays forever; a frozen migration that importedTypes.Notebecomes wrong the momentNotechanges in an incompatible way. Component-owned opaque state is the reason package imports are allowed:AccessControl.initState()frommo:caffeineai-authorization/access-controlcan only be constructed by importing the package. mops check --fixautomatically verifies upgrade compatibility.
Two Kinds of Migration
1. Implicit migration (no code)
The runtime allows the upgrade if the new program is compatible with the old. No migration function needed.
Do NOT add a migration file for changes in the implicit list below. Every migration file replays forever on fresh install; adding a no-op file bloats the chain, slows fresh installs, and creates a frozen artifact you can never delete. A long enough chain becomes undeployable in a way no retry recovers, and
mops checkwill not warn you. Fewer migrations are always better.Identity body = no migration. If your
(old : OldActor) : NewActorbody would just beold(or rebuild the same record field-by-field with no transformation), the change is stable-compatible — delete the file.Exception: never delete the first migration of a project converted from legacy persistence. Its
OldActoris non-empty and its body isold, but it is the base of the chain: deleting it removes the migration chain and undoes the conversion.
Allowed without explicit migration (typical compatible changes):
- Changing mutability of a field (
vartoletor vice versa) - Adding variant constructors
- Changing
NattoInt(and other safe supertypes) - Other changes that satisfy Motoko stable subtyping
Require explicit migration:
- Removing any actor field the
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- LICENSE
- SOURCE.md
- TRUST.auto.yaml
- references/examples.md
FAQ
Что делает скилл migrating-motoko-actors?
Motoko actor state migration and schema evolution using the mops-managed migration chain (a migrations/ directory of timestamped files). Use when upgrading canisters, changing actor field types, renaming or adding stable fields, deciding implicit vs explicit migration, or writing migration files — including one-shot changes. For unexplained compatibility diagnostics, frozen migration files, a non-empty first OldActor, projects converted from legacy persistence, or requests to remove the chain or revert to inline (with migration = ...), use troubleshooting-motoko-migrations.
Как установить скилл migrating-motoko-actors?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл migrating-motoko-actors запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…