Need to duplicate migration_defaults if multiple resources uses the same table

I have a resource called User it has this postgres configuration:
postgres do
table "users"

repo Marketplace.Repo

migration_defaults roles: "[\"seller\"]"
end
postgres do
table "users"

repo Marketplace.Repo

migration_defaults roles: "[\"seller\"]"
end
I have a migration file for that specific resource with correctly created the roles field with the default value:
add :roles, {:array, :text}, null: false, default: ["seller"]
add :roles, {:array, :text}, null: false, default: ["seller"]
I also have another resource that uses the same table called Bidder. it has this postgres configuration:
postgres do
table "users"

repo Marketplace.Repo
end
postgres do
table "users"

repo Marketplace.Repo
end
If I try to create a migration file for that resource, it will alter the user table changing the role default to nil. Can I stop it from doing it without having to duplicate that code in both resources?
2 Replies
ZachDaniel
ZachDaniel3y ago
You could do something like migration_ignore_attributes: [:foo] on one of the resources where :foo is the attribute you don’t want it to mess with If one of the resources is a strict subset of the other, you can also say migrate? false to only generate migrations based on the main resource.
Blibs
BlibsOP3y ago
Thank you, amazing how Ash always have a solution already in place hahaha

Did you find this page helpful?