Generates Ecto migrations for the Blockscout Elixir project using mix ecto.gen.migration command. Use when you need to create database schema changes, add tables, modify columns, or manage database structure.
The ecto-migration skill generates new Ecto migration files for the Blockscout project using the Mix task. Migrations are used to evolve the database schema over time in a versioned and controlled manner.
Run the following command from the workspace root:
mix ecto.gen.migration [migration_name] -r Explorer.Repo
Replace [migration_name] with a descriptive name for your migration using snake_case (e.g., add_users_table, alter_transactions_status).
apps/explorer/priv/repo/migrations/ directorychange/0 or up/0 and down/0 functionsExplorer.Repo repository specificallyGenerate a migration to add a new column:
mix ecto.gen.migration add_metadata_to_blocks -r Explorer.Repo
This creates a file like:
apps/explorer/priv/repo/migrations/20260220123456_add_metadata_to_blocks.exsThen edit the generated file to implement your schema changes:
defmodule Explorer.Repo.Migrations.AddMetadataToBlocks do
use Ecto.Migration
def change do
alter table(:blocks) do
add :metadata, :jsonb
end
end
end
-r Explorer.Repo flag specifies the repository (required for umbrella apps)mix ecto.migrate to apply the migration to your databasemix ecto.rollback to revert the last migration if neededup/0 and down/0 instead of change/0