Fix migration

This commit is contained in:
aignatov-bio 2019-10-07 13:54:38 +02:00
parent 5964a1b1f4
commit cb5baa3d13

View file

@ -4,7 +4,12 @@ class ConvertActivitiesJsonToJsonb < ActiveRecord::Migration[5.2]
def change
change_column :activities, :values, 'jsonb USING CAST(values AS jsonb)'
ActiveRecord::Base.connection.execute("
UPDATE activities SET values = REGEXP_REPLACE(values::text, '^\"||\"$||\\\\', '', 'g')::jsonb
UPDATE activities SET
values = REGEXP_REPLACE(
REGEXP_REPLACE(
REGEXP_REPLACE(values::text, '\\\\\"', '\"', 'g'),
'^\"||\"$', '', 'g'),
'\\\\\\\\', '\\\\', 'g')::jsonb
")
end
end