Korbin
Korbin
AEAsh Elixir
Created by moissela on 7/28/2023 in #support
Prefixed base62 UUIDv7 primary key implementation with Ash
Idk if Uniq’s maintainers would except an extension contribution in the first place, but why a new package vs contributing to existing package? I’m asking out curiosity as I don’t really know the advantages/disadvantages of either approach.
25 replies
AEAsh Elixir
Created by moissela on 7/28/2023 in #support
Prefixed base62 UUIDv7 primary key implementation with Ash
Are you still intending to release a completely new package or are you contributing that extension to Uniq?
25 replies
AEAsh Elixir
Created by moissela on 7/28/2023 in #support
Prefixed base62 UUIDv7 primary key implementation with Ash
@moissela I too was trying to figure out how to use UUIDv7. Made a support post about it as well. I was thinking yesterday that maybe it could be added to something like the uniq package. They already define extentions for Ecto here: https://github.com/bitwalker/uniq/blob/f229d462c939ec655dd8ac8abbfe7325f2e83e6e/lib/uuid.ex#L951. Someone could define extensions for Ash similarly.
25 replies
AEAsh Elixir
Created by Korbin on 8/3/2023 in #support
Should I use old-fashioned DB lookup tables? What might be some alternatives?
TLDR; Yes, you should probably in many cases still use old-fashioned lookup tables. This gives the benefit of run-time editability and additions of values. For key/value mappings that are super-definitely static, two options exist: Ash.Type.Enum and making your own custom type. For Enums, the atom is converted to a string (:ci_string I think) and stored in DB like that. This can fall prey to larger table storage as you're storing copies of each string as opposed to an ID pointing at the same value. Custom types can help with this since you can define two-way translations.
15 replies
AEAsh Elixir
Created by Korbin on 8/3/2023 in #support
Should I use old-fashioned DB lookup tables? What might be some alternatives?
Yeah, I think custom types is exactly what I'm looking for. I totally missed that section in the docs.
15 replies
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 see. I wish there was a callback or something to specify underlying value. Something like:
:high => 3
:med => 2
:low => 1
:high => 3
:med => 2
:low => 1
That'd make Enum basically a complete in-code replacement for a static lookup table in the DB. I suppose there's probably an escape hatch in Ash for something like this though. Be it in a code_interface or custom action or something like that.
15 replies
AEAsh Elixir
Created by Korbin on 8/3/2023 in #support
Should I use old-fashioned DB lookup tables? What might be some alternatives?
Okay, Ash.Type.Enum is a good callout for certain situations. Is there an example of that usage (didn't see one in ash_hq) and how it works with Postgres?
15 replies
AEAsh Elixir
Created by Korbin on 7/23/2023 in #support
Differences between UUID primary keys in Ecto vs Ash
TLDR; Don't worry about it if you're okay with your UUID being version 4. The end-of-the day for most projects will result in the same fuctionality. If you want to use a different UUID version for your PKs, manually write out an attribute DSL block and put your UUID-generating function capture in default. To sum up this post, my confusion around UUIDs in Ecto vs Ash came from comparing the migration files respectively. - Ecto uses type binary_id, Ash uses uuid; I have not verified this is exactly the same inside the DB - Ash adds the null: false bit when using uuid_primary_key - Ash adds an Ecto fragment for generating UUIDs on the DB even though Ash generates them in Elixir-land (as in the DB doesn't do it when using Ash); I haven't varified and wouldn't know how to - Ash's addition of the Ecto fragment only applies when when the default in the attribute DSL block is Ash's or Ecto's standard UUID generate function If wanting to use a different type of UUID, you cannot use uuid_primary_key at the time of writing. You will have to manually write out an attribute DSL block and use default (this applies to Elixir-land only) for generating the UUID primary key. If you'd like parity to Ash's magic fragment, you'll need to use the migration_defaults DSL in a postgres clause to do it. Don't know if I got the verbiage right.
31 replies
AEAsh Elixir
Created by Korbin on 7/23/2023 in #support
Differences between UUID primary keys in Ecto vs Ash
Okay, following up here and for posterity: more 2 questions. Question 1: your example @Zach Daniel:
attribute :id, UUIDv7, primary_key?: true, generated?: true, writable?: false, default: `UUIDv7.generate/0`
attribute :id, UUIDv7, primary_key?: true, generated?: true, writable?: false, default: `UUIDv7.generate/0`
The type (in this theoretical case "UUIDv7") concerns itself with decoding and encoding. The default concerns itself with generating a value and encoding to put into the database in Elixir-land for create actions. In this case, generated? should be false, right? Question 2: for UUIDs that we generate in Elixir-land, as is the case with default: &Ash.UUID.generate/0, what's the point of that magical ~S[fragment("uuid_generate_v4()")]?
31 replies
AEAsh Elixir
Created by Korbin on 7/23/2023 in #support
Differences between UUID primary keys in Ecto vs Ash
Okay, I will close this post soon. I want to read over it again and comment a summary before I do.
31 replies
AEAsh Elixir
Created by Korbin on 7/23/2023 in #support
Differences between UUID primary keys in Ecto vs Ash
Haha, there it is :thinkies:
31 replies
AEAsh Elixir
Created by Korbin on 7/23/2023 in #support
Differences between UUID primary keys in Ecto vs Ash
I swapped it for Ecto's function to see what'd it do and it still threw that on there. I'm testing writing my own to see what it does
31 replies
AEAsh Elixir
Created by Korbin on 7/23/2023 in #support
Differences between UUID primary keys in Ecto vs Ash
I see. Okay, I think that clears it up for me. My main confusion I think is seeing that fragment in the migrations. Seems to show up if type is :uuid no matter what.
31 replies
AEAsh Elixir
Created by Korbin on 7/23/2023 in #support
Differences between UUID primary keys in Ecto vs Ash
Okay, dropping PK scenario. What of these statements: generated false and default &MyMod.my_func/0 => value generated in Elixir-land generated true and default fragement("plugin_func()") => value generated in data-layer land (Postgres)
31 replies
AEAsh Elixir
Created by Korbin on 7/23/2023 in #support
Differences between UUID primary keys in Ecto vs Ash
What property tells it to generate ID in Elixir-land if not that one?
31 replies
AEAsh Elixir
Created by Korbin on 7/23/2023 in #support
Differences between UUID primary keys in Ecto vs Ash
Yeah, I've been playing with manually defining the PK via attribute DSL. Something I noticed is in the documentation online, they say that using uuid_primary_key is equivalent to what I wrote in my original post, but that might not be true. I noticed a file at resource_snapshots/repo/posts/yada-yada.json tells a different story. It says that generated? is false. Did I catch that right, or am I mistaken?
31 replies
AEAsh Elixir
Created by Korbin on 7/23/2023 in #support
Differences between UUID primary keys in Ecto vs Ash
Thanks for the info! I'm not quite a pro at navigating all the docs and source in Ash yet.
31 replies
AEAsh Elixir
Created by Korbin on 7/23/2023 in #support
Starting a Phoenix/Ash project with minimal cruft
Wow, this is such a "duh" moment. I assumed since the Phoenix guide didn't mention initializing Phoenix without Ecto meant there was some kind of plumbing that Ash relied on there in AshPhoenix
9 replies