Migrations create and modify the database tables Attached needs to function.
Usage
Generate a migration in your app:
mix attached.installThis creates a migration that delegates to Attached.Ecto.Migration:
defmodule MyApp.Repo.Migrations.CreateAttachedTables do
use Ecto.Migration
def up, do: Attached.Ecto.Migration.up()
def down, do: Attached.Ecto.Migration.down()
endUpgrading
When a new version of Attached requires schema changes, generate a new migration:
mix ecto.gen.migration upgrade_attached_to_v2Then call up with the target version:
def up, do: Attached.Ecto.Migration.up(version: 2)
def down, do: Attached.Ecto.Migration.down(version: 2)
Summary
Functions
Run all migrations down from the latest version, or a specific version.
Updates attached_originals ownership tracking when a field or table is renamed.
Run all migrations up to the latest version, or a specific version.
Functions
Run all migrations down from the latest version, or a specific version.
Updates attached_originals ownership tracking when a field or table is renamed.
Mirrors Ecto's rename/2,3 syntax — call it alongside the corresponding
Ecto rename in your migration.
Field rename
def up do
rename table(:users), :avatar_attached_original_id, to: :profile_picture_attached_original_id
Attached.Ecto.Migration.rename table(:users), :avatar, to: :profile_picture
end
def down do
rename table(:users), :profile_picture_attached_original_id, to: :avatar_attached_original_id
Attached.Ecto.Migration.rename table(:users), :profile_picture, to: :avatar
endTable rename
def up do
rename table(:users), to: table(:accounts)
Attached.Ecto.Migration.rename table(:users), to: table(:accounts)
end
def down do
rename table(:accounts), to: table(:users)
Attached.Ecto.Migration.rename table(:accounts), to: table(:users)
end
Run all migrations up to the latest version, or a specific version.