From cb5baa3d13fc40e24823680952968bbe46ba7388 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Mon, 7 Oct 2019 13:54:38 +0200 Subject: [PATCH] Fix migration --- .../20190903145834_convert_activities_json_to_jsonb.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/db/migrate/20190903145834_convert_activities_json_to_jsonb.rb b/db/migrate/20190903145834_convert_activities_json_to_jsonb.rb index 681393d8f..3dd998c09 100644 --- a/db/migrate/20190903145834_convert_activities_json_to_jsonb.rb +++ b/db/migrate/20190903145834_convert_activities_json_to_jsonb.rb @@ -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