Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fixed: proper json/jsonb check implemented (#13002)

Damian Legawiec80312bced4cc
diff --git a/core/db/migrate/20250605131334_add_missing_fields_to_users.rb b/core/db/migrate/20250605131334_add_missing_fields_to_users.rb
index a2c2f822f0..b7967b3bfb 100644
--- a/core/db/migrate/20250605131334_add_missing_fields_to_users.rb
+++ b/core/db/migrate/20250605131334_add_missing_fields_to_users.rb
@@ -1,25 +1,35 @@
-# this fields were not present when someone used a custom user class
+# these fields were not present when someone used a custom user class
# so we need to ensure this is setup properly
class AddMissingFieldsToUsers < ActiveRecord::Migration[7.2]
def change
users_table = Spree.user_class.table_name
- add_column users_table, :login, :string, if_not_exists: true
+ admin_users_table = Spree.admin_user_class.table_name
- json_type = if users_table.respond_to?(:jsonb)
- :jsonb
- else
- :json
- end
+ change_table users_table do |t|
+ t.string :login unless column_exists?(users_table, :login)
- add_column users_table, :public_metadata, json_type, if_not_exists: true
- add_column users_table, :private_metadata, json_type, if_not_exists: true
+ if t.respond_to? :jsonb
+ t.jsonb :public_metadata unless column_exists?(users_table, :public_metadata)
+ t.jsonb :private_metadata unless column_exists?(users_table, :private_metadata)
+ else
+ t.json :public_metadata unless column_exists?(users_table, :public_metadata)
+ t.json :private_metadata unless column_exists?(users_table, :private_metadata)
+ end
+ end
add_reference users_table, :bill_address, if_not_exists: true
add_reference users_table, :ship_address, if_not_exists: true
- admin_users_table = Spree.admin_user_class.table_name
- add_column admin_users_table, :login, :string, if_not_exists: true
- add_column admin_users_table, :public_metadata, json_type, if_not_exists: true
- add_column admin_users_table, :private_metadata, json_type, if_not_exists: true
+ change_table admin_users_table do |t|
+ t.string :login unless column_exists?(admin_users_table, :login)
+
+ if t.respond_to? :jsonb
+ t.jsonb :public_metadata unless column_exists?(admin_users_table, :public_metadata)
+ t.jsonb :private_metadata unless column_exists?(admin_users_table, :private_metadata)
+ else
+ t.json :public_metadata unless column_exists?(admin_users_table, :public_metadata)
+ t.json :private_metadata unless column_exists?(admin_users_table, :private_metadata)
+ end
+ end
end
end