Skip to content

Commit 9722411

Browse files
authored
Merge pull request #3886 from mamhoff/fix-mariadb-concat
2 parents 8c9969b + 210046a commit 9722411

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
class ConvertSelectValueForMultiple < ActiveRecord::Migration[7.1]
22
def up
33
say_with_time "Converting Alchemy::Ingredients::Select values to multiple" do
4-
update <<-SQL.squish
5-
UPDATE alchemy_ingredients
6-
SET value = '["' || value || '"]'
7-
WHERE type = 'Alchemy::Ingredients::Select' AND value NOT LIKE '["%"]';
8-
SQL
4+
Alchemy::Ingredients::Select
5+
.where.not("value LIKE ?", '["%')
6+
.update_all(
7+
Arel.sql(
8+
case ActiveRecord::Base.connection.adapter_name
9+
when /mysql|mariadb/i
10+
"value = CONCAT('[\"', value, '\"]')"
11+
else
12+
"value = '[\"' || value || '\"]'"
13+
end
14+
)
15+
)
916
end
1017
end
1118
end

0 commit comments

Comments
 (0)