Skip to content

Commit

Permalink
Merge pull request #6157 from blish/fix-metadata-users-migration
Browse files Browse the repository at this point in the history
Respect Spree.user_class' table name in metadata migration
  • Loading branch information
tvdeyen authored Feb 24, 2025
2 parents 2678765 + 1bcdfe4 commit eca889d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ def change
spree_refunds
spree_customer_returns
spree_store_credit_events
spree_users
spree_return_authorizations
].each do |table_name|
change_table table_name do |t|
# Check if the database supports jsonb for efficient querying
if t.respond_to?(:jsonb)
add_column table_name, :customer_metadata, :jsonb, default: {}
add_column table_name, :admin_metadata, :jsonb, default: {}
t.jsonb(:customer_metadata, default: {}) unless t.column_exists?(:customer_metadata)
t.jsonb(:admin_metadata, default: {}) unless t.column_exists?(:admin_metadata)
else
add_column table_name, :customer_metadata, :json
add_column table_name, :admin_metadata, :json
t.json(:customer_metadata) unless t.column_exists?(:customer_metadata)
t.json(:admin_metadata) unless t.column_exists?(:admin_metadata)
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions core/db/migrate/20250221152004_add_metadata_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class AddMetadataToUsers < ActiveRecord::Migration[7.0]
def change
change_table Spree.user_class.table_name do |t|
if t.respond_to?(:jsonb)
t.jsonb(:customer_metadata, default: {}) unless t.column_exists?(:customer_metadata)
t.jsonb(:admin_metadata, default: {}) unless t.column_exists?(:admin_metadata)
else
t.json(:customer_metadata) unless t.column_exists?(:customer_metadata)
t.json(:admin_metadata) unless t.column_exists?(:admin_metadata)
end
end
end
end

0 comments on commit eca889d

Please sign in to comment.