Ash FrameworkAF
Ash Framework3y ago
3 replies
Jason

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"

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
`
Was this page helpful?