database - How to modify field in ecto by Algorithm -
hello i'am looking method change field types , convert values during this.
mean that:
def alter table(:users) modify :role, :integer, default: fragment("convertion_function") end end i know ecto.migration#modify/3 function gets &fragment/1 argument. gets 1 argument.
know if possible pass current value &fragment/1 function?
or maybe know better way that?
in postgresql, can done specifying using clause alter table <table> alter column <column> query. couldn't find support in ecto's migration. can use execute execute raw query this. here's how you'd alter posts table's title column string integer , set new value length of original titles:
def execute """ alter table posts alter column title type integer using length(title); """ end length(title) being fragment expression calculates new value.
you'll want write similar query reverse migration well.
you can read more using in alter table here.
Comments
Post a Comment