Skip to content

Commit 210046a

Browse files
committed
Fix: Allow Multiple Select migration to work with MariaDB
MariaDB/MySQL do not support the `||` operator for string concatenation (they treat it as a logical "or"). This commit converts the syntax to ActiveRecord and uses `CONCAT` for MariaDB and MySQL. Apparently, SQlite does not support `CONCAT`, and needs the pipes.
1 parent ed95633 commit 210046a

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)