How to assign a default value to existing rows via Ash.postgres generated migration code

When a non-null column is added, is there a way to specify a default value to assign to the new column for existing records? I believe in Ecto, it's done something like this, but I'm curious if this can be done through Ash DSL.
add :new_field, :string, default: "default value"
add :new_field, :string, default: "default value"
If it makes a difference, the new column in my case is a source attribute for a relationship as in something like this. (So manually adding default: "default value" actually causes a foreign_key_violation., which is a different issue on its own.)
belongs_to :theme, Items.Theme do
api Items
allow_nil? false
destination_attribute :destination_new_field
source_attribute :new_field
attribute_type :integer
end
belongs_to :theme, Items.Theme do
api Items
allow_nil? false
destination_attribute :destination_new_field
source_attribute :new_field
attribute_type :integer
end
`
2 Replies
ZachDaniel
ZachDaniel2y ago
For that one if you define the theme_id attribute yourself you can then set a default Then set define_attribute false to prevent the relationship from trying to also add that attribute m
Jason
JasonOP2y ago
Okay. Thank you!

Did you find this page helpful?