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
serialize
column real array column 1. - remove
serialize
declaration model. - drop old column
serialize
used. - rename column 1.
- set newly renamed column
not null
if desired.
you parse yaml inside database using regex , string functions depend on sorts of things you're storing in yaml.
Comments
Post a Comment