Korbin
Korbin
AEAsh Elixir
Created by Korbin on 8/3/2023 in #support
Should I use old-fashioned DB lookup tables? What might be some alternatives?
I realize not all mapped values are the same. Some have a very small set number of KVs (int id => 5-point scale). Some have a larger (int id => country code). Some have an indefinite set of KVs. In which cases (if not all) would you recommend DB lookup tables with Ash relationships. Would you recommend an alternative? I had considered for small sets to use a calculation, but I think that works with reads but not writes, right?
15 replies
AEAsh Elixir
Created by Korbin on 7/23/2023 in #support
Differences between UUID primary keys in Ecto vs Ash
As far as I can tell, the Ash Resource special attribute uuid_primary_key unwraps into:
attribute :id, :uuid do
writeable? false
default &Ash.UUID.generate/0
primary_key? true
allow_nil? false
end
attribute :id, :uuid do
writeable? false
default &Ash.UUID.generate/0
primary_key? true
allow_nil? false
end
Ash.UUID.generate/0 seems to be a passthrough to Ecto.UUID.generate(). What I found unexpected was the migration files. Echo's migration file looks like:
...
def change do
create table(:posts, primary_key: false) do
add :id, :binary_id, primary_key: true
...
end
end
...
def change do
create table(:posts, primary_key: false) do
add :id, :binary_id, primary_key: true
...
end
end
Ash's migration file looks like:
def up do
create table(:posts, primary_key: false) do
add :id, :uuid, null: false, default: fragment("uuid_generate_v4()"), primary_key: true
...
end
end
def up do
create table(:posts, primary_key: false) do
add :id, :uuid, null: false, default: fragment("uuid_generate_v4()"), primary_key: true
...
end
end
I'm not entirely sure if the functionality will all be the same at the end of the day. Reading docs and source code, it seems like Postgrex treats :binary, :binary_id, and :uuid similarly when ran by Ecto SQL, but I'm not sure. The most surprising is the :default option in Ash's implementation. It hard-codes a Postgres DB function as a default value even though :primary_key option is set (which I think inherently makes the field non-nullable in most databases. The reason I'm worried about it is because I'm interested in using UUIDv7 for my PKs. That function may never run if generating UUIDs in Elixir-land, but it seems off to be there.
31 replies
AEAsh Elixir
Created by Korbin on 7/23/2023 in #support
Starting a Phoenix/Ash project with minimal cruft
Howdy there. I've been trying the tutorials from the Ash website (both "Get Started" and "Get Started with Ash and Phoenix"). As I was going through, I couldn't help but wonder, "is there a way to do this without Phoenix's Ecto?" In other words, if I'm planning on using Ash for all the domain logic, and Ash is going to use Ecto, can I initialize Pheonix without ecto and still get Ash to work right (since I'll be using Ecto with it)? Context:
mix phx.new my_cool_app --no-ecto
mix phx.new my_cool_app --no-ecto
And then use Ash with AshPostgres.
9 replies