Ash FrameworkAF
Ash Framework3y ago
4 replies
Robert Graff

Guides or advice for migrating to Ash?

I have a small app with 3 tables in Postgres using Ecto.Table. I am migrating them to use Ash.Resource.

When I run mix ash_postgres.generate_migrations for the first time, the generated migrations are to create tables that already exist and the table structures are different. Are there any guides or do you have any advice for reconciling the differences?

Original ecto migration:

defmodule Iterup.Repo.Migrations.CreateAccounts do
  use Ecto.Migration

  def change do
    create table(:accounts, primary_key: false) do
      add :id, :binary_id, primary_key: true
      add :name, :string
      add :slug, :string

      timestamps()
    end

    create unique_index(:accounts, [:slug])
  end
end


New generated migration:

defmodule Iterup.Repo.Migrations.MigrateResources1 do
  @moduledoc """
  Updates resources based on their most recent snapshots.

  This file was autogenerated with `mix ash_postgres.generate_migrations`
  """

  use Ecto.Migration

  def up do
    create table(:accounts, primary_key: false) do
      add :id, :uuid, null: false, default: fragment("uuid_generate_v4()"), primary_key: true
      add :name, :text, null: false
      add :slug, :text, null: false
      add :inserted_at, :utc_datetime_usec, null: false, default: fragment("now()")
      add :updated_at, :utc_datetime_usec, null: false, default: fragment("now()")
    end
  end

  def down do
    drop table(:accounts)
  end
end


Thanks in advance. Excited to move to Ash.
Was this page helpful?