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.

Fix: Restored per-row timestamps on bulk inserts

Claude27fee714eda9
diff --git a/spree/core/app/models/spree/catalog.rb b/spree/core/app/models/spree/catalog.rb
index a049d4e2b2..092c58c14a 100644
--- a/spree/core/app/models/spree/catalog.rb
+++ b/spree/core/app/models/spree/catalog.rb
@@ -288,10 +288,14 @@ module Spree
new_ids = product_ids.uniq.select { |id| allowed_ids.include?(id) && !taken_ids.include?(id) }
return 0 if new_ids.empty?
+ now = Time.current
+
rows = new_ids.map do |product_id|
{
catalog_id: id,
- product_id: product_id
+ product_id: product_id,
+ created_at: now,
+ updated_at: now
}
end
diff --git a/spree/core/app/models/spree/customer_group.rb b/spree/core/app/models/spree/customer_group.rb
index 00e58c02a9..0bfbbbd33c 100644
--- a/spree/core/app/models/spree/customer_group.rb
+++ b/spree/core/app/models/spree/customer_group.rb
@@ -48,6 +48,7 @@ module Spree
# Get existing user IDs to avoid duplicates
existing_user_ids = customer_group_users.where(customer_id: user_ids).pluck(:customer_id).map(&:to_s).to_set
+ now = Time.current
user_type = Spree.customer_class.to_s
records_to_insert = user_ids.filter_map do |user_id|
@@ -56,7 +57,9 @@ module Spree
{
customer_group_id: id,
user_id: user_id,
- user_type: user_type
+ user_type: user_type,
+ created_at: now,
+ updated_at: now
}
end
diff --git a/spree/core/app/models/spree/price_list.rb b/spree/core/app/models/spree/price_list.rb
index 39bf191023..9105d02b2e 100644
--- a/spree/core/app/models/spree/price_list.rb
+++ b/spree/core/app/models/spree/price_list.rb
@@ -313,6 +313,8 @@ module Spree
.pluck(:variant_id, :currency)
.to_set
+ now = Time.current
+
prices_to_insert = variant_ids.flat_map do |variant_id|
currencies.filter_map do |currency|
next if existing.include?([variant_id, currency])
@@ -322,7 +324,9 @@ module Spree
currency: currency,
amount: nil,
min_quantity: 1,
- price_list_id: id
+ price_list_id: id,
+ created_at: now,
+ updated_at: now
}
end
end
diff --git a/spree/core/app/services/spree/collections/regenerate_products.rb b/spree/core/app/services/spree/collections/regenerate_products.rb
index 298cadafb3..4bb4bd8876 100644
--- a/spree/core/app/services/spree/collections/regenerate_products.rb
+++ b/spree/core/app/services/spree/collections/regenerate_products.rb
@@ -57,7 +57,9 @@ module Spree
{
product_id: product_id,
collection_id: collection.id,
- position: position
+ position: position,
+ created_at: Time.current,
+ updated_at: Time.current
}
end
end
diff --git a/spree/core/app/services/spree/coupon_codes/bulk_generate.rb b/spree/core/app/services/spree/coupon_codes/bulk_generate.rb
index 8a7b6b1aa6..4537b1ec26 100644
--- a/spree/core/app/services/spree/coupon_codes/bulk_generate.rb
+++ b/spree/core/app/services/spree/coupon_codes/bulk_generate.rb
@@ -6,7 +6,12 @@ module Spree
def call(promotion:, quantity: 10)
Spree::CouponCode.transaction do
Spree::CouponCode.insert_all(
- Array.new(quantity) { { promotion_id: promotion.id, code: create_code(promotion.code_prefix) } }
+ Array.new(quantity) do
+ {
+ promotion_id: promotion.id, code: create_code(promotion.code_prefix),
+ created_at: Time.current, updated_at: Time.current
+ }
+ end
)
end
diff --git a/spree/core/app/services/spree/product_memberships.rb b/spree/core/app/services/spree/product_memberships.rb
index ba2b59a1de..3fbc6572b2 100644
--- a/spree/core/app/services/spree/product_memberships.rb
+++ b/spree/core/app/services/spree/product_memberships.rb
@@ -10,7 +10,10 @@ module Spree
rows = groups.pluck(:id).flat_map do |group_id|
position = membership_class.where(group_key => group_id).count
products.pluck(:id).map do |product_id|
- { group_key => group_id, product_id: product_id, position: (position += 1) }
+ {
+ group_key => group_id, product_id: product_id, position: (position += 1),
+ created_at: Time.current, updated_at: Time.current
+ }
end
end
membership_class.insert_all(rows)
@@ -27,7 +30,10 @@ module Spree
rows = group_ids.flat_map do |group_id|
membership_class.where(group_key => group_id).order(:position).pluck(:product_id).map.with_index(1) do |product_id, position|
- { group_key => group_id, product_id: product_id, position: position }
+ {
+ group_key => group_id, product_id: product_id, position: position,
+ created_at: Time.current, updated_at: Time.current
+ }
end
end
membership_class.upsert_all(rows, unique_by: ([group_key, :product_id] unless Spree.mysql?)) if rows.any?
diff --git a/spree/core/app/services/spree/products/auto_match_collections.rb b/spree/core/app/services/spree/products/auto_match_collections.rb
index c11fa6f075..dd289dfdc9 100644
--- a/spree/core/app/services/spree/products/auto_match_collections.rb
+++ b/spree/core/app/services/spree/products/auto_match_collections.rb
@@ -65,7 +65,9 @@ module Spree
{
collection_id: collection.id,
product_id: product.id,
- position: position
+ position: position,
+ created_at: Time.current,
+ updated_at: Time.current
}
end
end
diff --git a/spree/core/app/services/spree/stores/provision_defaults.rb b/spree/core/app/services/spree/stores/provision_defaults.rb
index 048382591a..92f4788e18 100644
--- a/spree/core/app/services/spree/stores/provision_defaults.rb
+++ b/spree/core/app/services/spree/stores/provision_defaults.rb
@@ -167,12 +167,15 @@ module Spree
missing = isos - existing.reload.pluck(:country_code)
return if missing.empty?
+ now = Time.current
Spree::DeliveryZoneMember.insert_all(
missing.map do |iso|
{
delivery_zone_id: zone.id,
member_type: 'country',
- country_code: iso
+ country_code: iso,
+ created_at: now,
+ updated_at: now
}
end
)