From 0ffa7b373482ccb4ad28d0d0e699c15685c453b6 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 23 Jun 2020 16:17:25 +0200 Subject: [PATCH 1/3] Migrate all spree pref. keys to the new format We realized in Spree v2.1 they follow this format instead and this is what's causing issues to Katuma production. This will remove the duplicate ones and convert the current preferences to the new thus, keeping the values. --- db/migrate/20200623140437_fix_preferences_keys.rb | 11 +++++++++++ db/schema.rb | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20200623140437_fix_preferences_keys.rb diff --git a/db/migrate/20200623140437_fix_preferences_keys.rb b/db/migrate/20200623140437_fix_preferences_keys.rb new file mode 100644 index 0000000000..aed5e39053 --- /dev/null +++ b/db/migrate/20200623140437_fix_preferences_keys.rb @@ -0,0 +1,11 @@ +class FixPreferencesKeys < ActiveRecord::Migration + def up + new_preferences = Spree::Preference.where("key like '/%'") + new_preferences.delete_all + + Spree::Preference.update_all("key = '/' || key") + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index e2ec79428a..d166fdfd3c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20200508101630) do +ActiveRecord::Schema.define(version: 20200623140437) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From 190797717a9d086d958d3c58602d0739c0197a03 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 23 Jun 2020 17:22:11 +0200 Subject: [PATCH 2/3] Defend from the running the migration twice We only migrate preferences if there are any to migrate. --- db/migrate/20200623140437_fix_preferences_keys.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/migrate/20200623140437_fix_preferences_keys.rb b/db/migrate/20200623140437_fix_preferences_keys.rb index aed5e39053..c9a76b8b14 100644 --- a/db/migrate/20200623140437_fix_preferences_keys.rb +++ b/db/migrate/20200623140437_fix_preferences_keys.rb @@ -1,6 +1,9 @@ class FixPreferencesKeys < ActiveRecord::Migration def up - new_preferences = Spree::Preference.where("key like '/%'") + unmigrated_preferences = Spree::Preference.exists?(['key NOT LIKE ?', '/%']) + return unless unmigrated_preferences + + new_preferences = Spree::Preference.where("key LIKE '/%'") new_preferences.delete_all Spree::Preference.update_all("key = '/' || key") From a81e17f23cf4dc4288071f5559cd8072ce183f93 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 23 Jun 2020 17:23:22 +0200 Subject: [PATCH 3/3] Flush the cache So all preferences are fetch from DB now that they have changed. --- db/migrate/20200623140437_fix_preferences_keys.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/migrate/20200623140437_fix_preferences_keys.rb b/db/migrate/20200623140437_fix_preferences_keys.rb index c9a76b8b14..3f024ee278 100644 --- a/db/migrate/20200623140437_fix_preferences_keys.rb +++ b/db/migrate/20200623140437_fix_preferences_keys.rb @@ -7,6 +7,8 @@ class FixPreferencesKeys < ActiveRecord::Migration new_preferences.delete_all Spree::Preference.update_all("key = '/' || key") + + Rails.cache.clear end def down