mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-31 06:31:41 +00:00
Add migration to fix calculator preferences
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
# As we moved the calculators outside the Spree namespace in migration MoveAllCalculatorsOutsideTheSpreeNamespace
|
||||
# We need to move their preferences too (currency, value, etc), otherwise they are not used
|
||||
class MoveCalculatorsPreferencesOutsideSpreeNamespace < ActiveRecord::Migration
|
||||
def up
|
||||
replace_preferences_key("/spree/calculator", "/calculator")
|
||||
end
|
||||
|
||||
def down
|
||||
replace_preferences_key("/calculator", "/spree/calculator")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def replace_preferences_key(from_pattern, to_pattern)
|
||||
updated_pref_key = "replace( pref.key, '" + from_pattern + "', '" + to_pattern + "')"
|
||||
Spree::Preference.connection.execute(
|
||||
"UPDATE spree_preferences pref SET key = " + updated_pref_key + "
|
||||
WHERE pref.key like '" + from_pattern + "%'
|
||||
AND NOT EXISTS (SELECT 1 FROM spree_preferences existing_pref
|
||||
WHERE existing_pref.key = " + updated_pref_key + ")"
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20200702112157) do
|
||||
ActiveRecord::Schema.define(version: 20200721135726) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
Reference in New Issue
Block a user