ecto-migrations

Enforces rules for creating Ecto schema migrations and Operately data change modules.

553|70|Updated Feb 28, 2023
One-click install
npx skills add https://github.com/operately/operately --skill ecto-migrations-operately
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: ecto-migrations
Source: https://github.com/operately/operately/tree/main/.agents/skills/ecto-migrations
Command: npx skills add https://github.com/operately/operately --skill ecto-migrations-operately

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Database migrations in the Operately codebase fail when developers hand-create migration files with colliding timestamp versions or when data migrations reference live application schemas that change over time, causing broken fresh installs and production errors like duplicate_column failures. ## Core Features & Use Cases - Schema migration generation: Mandates creating migration files via make gen.migration NAME=... so Ecto receives unique timestamp versions instead of hand-written filenames that collide across PRs. - Data migration pattern: Directs backfills into Operately.Data.ChangeNNN* modules under app/lib/operately/data/, invoked from thin schema migrations whose up/0 only delegates to ChangeNNN.run(). - Inline schema isolation: Requires data migrations to define minimal inline structs instead of aliasing live modules like Operately.Goals.Goal, preventing breakage on fresh installs months later. - Use Case: When adding a column that needs existing rows backfilled, generate the schema migration with make gen.migration, create the next-numbered change_NNN_*.ex module with an idempotent run/0, and add a matching test under app/test/operately/data/. ## Quick Start Ask the agent to create an Ecto migration that adds a new column and backfills existing rows following the Operately migration rules.

Frequently Asked Questions about ecto-migrations

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create an Ecto migration in the Operately codebase?▼

Run `make gen.migration NAME=add_foo_to_bars`, which executes `mix ecto.gen.migration` inside devenv and assigns a unique timestamp version. Never create or copy migration files by hand, since manual timestamps collide across PRs and cause skipped or re-run migrations.

How do I write a data migration or backfill in Operately?▼

Create a module `Operately.Data.ChangeNNNDescriptiveName` in `app/lib/operately/data/change_NNN_descriptive_name.ex` with a `run/0` entry point, using the next unused change number. Then write a thin schema migration whose `up/0` calls `ChangeNNN.run()`.

Why do Ecto migration timestamps collide across branches?▼

Ecto keys migrations by the numeric filename prefix only, so two hand-written files with the same timestamp cause duplicates, skipped migrations, and production failures like duplicate_column errors. Generating via `make gen.migration` on an up-to-date main avoids the collision.

Can Ecto data migrations reference application schema modules?▼

No. Data migrations must not alias live modules like `Operately.Goals.Goal` because those modules change over time and break migrations on fresh installs. Define minimal inline structs inside the change module with only the fields the migration needs.

Should data migrations be idempotent and tested?▼

Yes. Prefer an idempotent `run/0` that is safe if re-run or if some rows already match the target state. Add tests under `app/test/operately/data/change_NNN_*_test.exs` following existing change module test examples.