ruby on rails - How to migrate from ActiveRecord's Serialize Array to Postgres Array datatype -
rails 4 supports postgres' array data type, , want start taking advantage of array types in postgres , how can migrate existing activerecord serialized array field new data type?
serialize stores things inside database yaml documents in text column. yaml isn't easiest format work inside database straightforward approach to:
- add array column hold arrays.
- loop through each record in rails, let activerecord unserialize yaml, copy ruby arrays
serializecolumn real array column 1. - remove
serializedeclaration model. - drop old column
serializeused. - rename column 1.
- set newly renamed column
not nullif desired.
you parse yaml inside database using regex , string functions depend on sorts of things you're storing in yaml.
Comments
Post a Comment