Token导航 LogoToken导航TokenDH.com
开发只读clawhub未标认证来源可访问clear审计通过

ecto-migrator体外移行者

Agent Skill

ecto-migrator 用于处理数据库查询、表结构、迁移和数据维护任务,适合在 OpenClaw 中需要分析 schema、编写 SQL 或排查数据问题时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

54,103

周安装

2,324

GitHub Stars

1

下载量

18,964
OpenClaw

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

MIT-0

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:ecto-migrator(体外移行者)
来源仓库:https://github.com/gchapim/ecto-migrator
安装命令:
openclaw skills install ecto-migrator
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 OpenClaw 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

ClawHubOpenClaw
openclaw skills install ecto-migrator

简介

从自然语言或模式描述生成 Ecto 迁移。处理表、列、索引、约束、引用、枚举和分区。支持可逆迁移、数据迁移和多租户模式。在 Elixir 项目中创建或修改数据库模式、添加索引、更改表、创建枚举或执行数据迁移时使用。

SKILL.md

name
ecto-migrator
description
Generate Ecto migrations from natural language or schema descriptions. Handles tables, columns, indexes, constraints, references, enums, and partitioning. Supports reversible migrations, data migrations, and multi-tenant patterns. Use when creating or modifying database schemas, adding indexes, altering tables, creating enums, or performing data migrations in an Elixir project.

Ecto Migrator

Generating Migrations

From Natural Language

Parse the user's description and generate a migration file. Common patterns:

User SaysMigration Action
"Create users table with email and name"create table(:users) with columns
"Add phone to users"alter table(:users), add :phone
"Make email unique on users"create unique_index(:users, [:email])
"Add tenant_id to all tables"Multiple alter table with index
"Rename status to state on orders"rename table(:orders), :status, to: :state
"Remove the legacy_id column from users"alter table(:users), remove :legacy_id
"Add a check constraint on orders amount > 0"create constraint(:orders, ...)

File Naming

mix ecto.gen.migration <name>
# Generates: priv/repo/migrations/YYYYMMDDHHMMSS_<name>.exs

Name conventions: create_<table>, add_<column>_to_<table>, create_<table>_<column>_index, alter_<table>_add_<columns>.

Migration Template

defmodule MyApp.Repo.Migrations.CreateUsers do
  use Ecto.Migration

  def change do
    create table(:users, primary_key: false) do
      add :id, :binary_id, primary_key: true
      add :email, :string, null: false
      add :name, :string, null: false
      add :role, :string, null: false, default: "member"
      add :metadata, :map, default: %{}
      add :tenant_id, :binary_id, null: false

      add :team_id, references(:teams, type: :binary_id, on_delete: :delete_all)

      timestamps(type: :utc_datetime_usec)
    end

    create unique_index(:users, [:tenant_id, :email])
    create index(:users, [:tenant_id])
    create index(:users, [:team_id])
  end
end

Column Types

See references/column-types.md for complete type mapping and guidance.

Key decisions:

  • IDs: Use :binary_id (UUID) — set primary_key: false on table, add :id manually.
  • Money: Use :integer (cents) or :decimal — never :float.
  • Timestamps: Always timestamps(type: :utc_datetime_usec).
  • Enums: Use :string with app-level Ecto.Enum — avoid Postgres enums (hard to migrate).
  • JSON: Use :map (maps to jsonb).
  • Arrays: Use {:array, :string} etc.

Index Strategies

See references/index-patterns.md for detailed index guidance.

When to Add Indexes

Always index:

  • Foreign keys (_id columns)
  • tenant_id (first column in composite indexes)
  • Columns used in WHERE clauses
  • Columns used in ORDER BY
  • Unique constraints

Index Types

# Standard B-tree
create index(:users, [:tenant_id])

# Unique
create unique_index(:users, [:tenant_id, :email])

# Partial (conditional)
create index(:orders, [:status], where: "status != 'completed'", name: :orders_active_status_idx)

# GIN for JSONB
create index(:events, [:metadata], using: :gin)

# GIN for array columns
create index(:posts, [:tags], using: :gin)

# Composite
create index(:orders, [:tenant_id, :status, :inserted_at])

# Concurrent (no table lock — use in separate migration)
@disable_ddl_transaction true
@disable_migration_lock true

def change do
  create index(:users, [:email], concurrently: true)
end

Constraints

# Check constraint
create constraint(:orders, :amount_must_be_positive, check: "amount > 0")

# Exclusion constraint (requires btree_gist extension)
execute "CREATE EXTENSION IF NOT EXISTS btree_gist", ""
create constraint(:reservations, :no_overlapping_bookings,
  exclude: ~s|gist (room_id WITH =, tstzrange(starts_at, ends_at) WITH &&)|
)

# Unique constraint (same as unique_index for most purposes)
create unique_index(:accounts, [:slug])

References (Foreign Keys)

add :user_id, references(:users, type: :binary_id, on_delete: :delete_all), null: false
add :team_id, references(:teams, type: :binary_id, on_delete: :nilify_all)
add :parent_id, references(:categories, type: :binary_id, on_delete: :nothing)
on_deleteUse When
:delete_allChild can't exist without parent (memberships, line items)
:nilify_allChild should survive parent deletion (optional association)
:nothingHandle in application code (default)
:restrictPrevent parent deletion if children exist

Multi-Tenant Patterns

Every Table Gets tenant_id

def change do
  create table(:items, primary_key: false) do
    add :id, :binary_id, primary_key: true
    add :name, :string, null: false
    add :tenant_id, :binary_id, null: false
    timestamps(type: :utc_datetime_usec)
  end

  # Always composite index with tenant_id first
  create index(:items, [:tenant_id])
  create unique_index(:items, [:tenant_id, :name])
end

Adding tenant_id to Existing Tables

def change do
  alter table(:items) do
    add :tenant_id, :binary_id
  end

  # Backfill in a separate data migration, then:
  # alter table(:items) do
  #   modify :tenant_id, :binary_id, null: false
  # end
end

Data Migrations

Rule: Never mix schema changes and data changes in the same migration.

Safe Data Migration Pattern

defmodule MyApp.Repo.Migrations.BackfillUserRoles do
  use Ecto.Migration

  # Don't use schema modules — they may change after this migration runs
  def up do
    execute """
    UPDATE users SET role = 'member' WHERE role IS NULL
    """
  end

  def down do
    # Data migrations may not be reversible
    :ok
  end
end

Batched Data Migration (large tables)

def up do
  execute """
  UPDATE users SET role = 'member'
  WHERE id IN (
    SELECT id FROM users WHERE role IS NULL LIMIT 10000
  )
  """

  # For very large tables, use a Task or Oban job instead
end

Reversible vs Irreversible

Reversible (use change)

These are auto-reversible:

  • create tabledrop table
  • add columnremove column
  • create indexdrop index
  • renamerename

Irreversible (use up/down)

Must define both directions:

  • modify column type — Ecto can't infer the old type
  • execute raw SQL
  • Data backfills
  • Dropping columns with data
def up do
  alter table(:users) do
    modify :email, :citext, from: :string  # from: helps reversibility
  end
end

def down do
  alter table(:users) do
    modify :email, :string, from: :citext
  end
end

Using modify with from:

Phoenix 1.7+ supports from: for reversible modify:

def change do
  alter table(:users) do
    modify :email, :citext, null: false, from: {:string, null: true}
  end
end

PostgreSQL Extensions

def change do
  execute "CREATE EXTENSION IF NOT EXISTS citext", "DROP EXTENSION IF EXISTS citext"
  execute "CREATE EXTENSION IF NOT EXISTS pgcrypto", "DROP EXTENSION IF EXISTS pgcrypto"
  execute "CREATE EXTENSION IF NOT EXISTS pg_trgm", "DROP EXTENSION IF EXISTS pg_trgm"
end

Enum Types (PostgreSQL native — use sparingly)

Prefer Ecto.Enum with :string columns. If you must use Postgres enums:

def up do
  execute "CREATE TYPE order_status AS ENUM ('pending', 'confirmed', 'shipped', 'delivered')"

  alter table(:orders) do
    add :status, :order_status, null: false, default: "pending"
  end
end

def down do
  alter table(:orders) do
    remove :status
  end

  execute "DROP TYPE order_status"
end

Warning: Adding values to Postgres enums requires ALTER TYPE ... ADD VALUE which cannot run inside a transaction. Prefer :string + Ecto.Enum.

Checklist

  • [ ] Primary key: primary_key: false + add :id, :binary_id, primary_key: true
  • [ ] null: false on required columns
  • [ ] timestamps(type: :utc_datetime_usec)
  • [ ] Foreign keys with appropriate on_delete
  • [ ] Index on every foreign key column
  • [ ] tenant_id indexed (composite with lookup fields)
  • [ ] Unique constraints where needed
  • [ ] Concurrent indexes in separate migration with @disable_ddl_transaction true
  • [ ] Data migrations in separate files from schema migrations

适合场景

01

OpenClaw 用户查找和安装 Skill 时

02

用户想查找某类 Agent Skill 时

03

需要根据任务场景推荐可安装能力包时

04

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

OpenClaw

94.2%
按下载量换算17,864

安全审计

VirusTotal

通过

ClawScan

通过

Static analysis

未展示

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills