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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -