Command Palette

Search for a command to run...

Назад к скиллам
скилл № 11820

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от 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 as chain = ... under [canisters.<name>.migrations] in mops.toml; an imported project using a non-default canister name may place it elsewhere — read mops.toml rather than assuming.)
  • At most one pending migration per build (check-limit = 1 in mops.toml). If a migration is already pending (not yet applied), edit that file to fold in further changes instead of adding another. mops check compares the deployed .most baseline 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 and check-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 (no AddPriority, 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 ../types or any project module. The chain replays forever; a frozen migration that imported Types.Note becomes wrong the moment Note changes in an incompatible way. Component-owned opaque state is the reason package imports are allowed: AccessControl.initState() from mo:caffeineai-authorization/access-control can only be constructed by importing the package.
  • mops check --fix automatically 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 check will not warn you. Fewer migrations are always better.

Identity body = no migration. If your (old : OldActor) : NewActor body would just be old (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 OldActor is non-empty and its body is old, 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 (var to let or vice versa)
  • Adding variant constructors
  • Changing Nat to Int (and other safe supertypes)
  • Other changes that satisfy Motoko stable subtyping

Require explicit migration:

  • Removing any actor field the
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • 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), без исполняемых скриптов.

Похожие скиллы

Сравнить migrating-motoko-actors с