Not creating v7 uuids for ids
I'm using Ash 3.5 with AshPostgres.
I have a Country resource with the following
id
attribute:
1. Create the table using Ash-generated migration
1a. Here's the generated extensions.json
snapshot:
2. Populate the countries table via mix run priv/repo/seeds.exs
See https://gist.github.com/dev-guy/7d8617b5da2d4207accf3365e88eb7fc for the seeder module.
3. Select * from countries
4. Notice that all of the id
column values look like: 0f5f52a7-0ef0-445c-a59c-aacbcc56198a
These are not v7 uuids. The number after the second hyphen is a 4, so they are v4 uuids.
Have I not configured something correctly? Is this only a problem for seed data?
4a. Here is a uuid tester for reference:
Solution:Jump to solution
```elixir
change fn changeset, _context ->
if is_nil(Ash.Changeset.get_attribute(changeset, :id)) do
Ash.Changeset.force_change_attribute(changeset, :id, Ash.UUID.generate()) # <- this is in your code you sent
else...
20 Replies
What is ash-uuid_v2?
What do your seeds look like?
I see it. Umm...pretty weird? I know it makes valid v7 uuids
What does
Ash.Resource.Info.attribute(Resource, :id)
show?
Can you share the whole resource?If you don't know what ash-uuid_v2 is, I'll remove it.
Well, hold on
š
Just show me the resource first if you can
I am using a base resource so it's not as simple as it sounds.
https://gist.github.com/dev-guy/60c2355508fed8450e4b78fa61ff6690
https://gist.github.com/dev-guy/94d2767876d06fbe156f0dc5d987a190
Also, I don't know how ash-uuid_v2 got there.
And I don't know how to remove it. Grepping my codebase doesn't show it except in the snapshot.
BTW I'm also using ash-oban.
OK, what I couldn't find is in
repo.ex
. I was following some (probably old) documentation and added uuid-ossp and AshUUID.PostgresExtension in my sleep. I'll remove those and see what happens.
It's still creating v7 uuids (at least when creating seed data) with the following repo/extensions
snapshot
mix run priv/repo/seeds.exs
outputs :
Here is the Country resource.
:id
looks correct, but creating an instance using a changeset creates a v4 uuid.Ash.UUIDv7.generate
works correctly. Apparently Ash is not actually calling it.WHat does your database show for the underlying type?
Did you change from uuuid to uuidv7 and forget to run
mix ash.codegen
?I've been running
mix ash.codegen
many times due to regenerating the repo/extensions
snapshot . I also delete all of the migrations before that.
š¤ š¤ š¤
I don't understand how you could possibly be getting a regular uuid
š
you're doing it š
The issue has to do with creating instances of Country resource. The
id
attribute is configured to call Ash.UUIDv7.generate
, but creating a resource via a changeset is calling Ash.UUID.generate
š¤
On the create action you are calling
you're setting the id to a uuid v4
Solution
Yeah, I removed that.
and you recompiled and tried again?
it won't fix the existing uuids in your database
Right, I blow it away and start over. I will
mix clean
again.I'm like...99% positive that its something in your code somehow setting these values to uuid v4s
Sorry for wasting your time.
no need to apologize
I'm not upset š
I'm pretty sure if I hadn't fallen down this rabbit hole I would not have found out that user uuids were also v4, minor issue.
Yep, rebuilding fixed it. Footgun.
Oh, it was also useful to ask to get rid of the unnecessary extensions I added to the repo.