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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Keep the earning key off the auto-increment column
Damian Legawiecbdff55527dae
diff --git a/spree/core/db/migrate/20260822000001_create_spree_seller_transfers.rb b/spree/core/db/migrate/20260822000001_create_spree_seller_transfers.rbindex 4c954872e5..3f9fe70fb1 100644--- a/spree/core/db/migrate/20260822000001_create_spree_seller_transfers.rb+++ b/spree/core/db/migrate/20260822000001_create_spree_seller_transfers.rb@@ -56,13 +56,18 @@ class CreateSpreeSellerTransfers < ActiveRecord::Migration[8.1]else# MySQL and MariaDB have no partial index, and functional indexes are# MySQL-only — MariaDB rejects the expression outright. A stored- # generated column is the one spelling both accept: it holds the order- # for an earning and the row's own id otherwise, so earnings collide on- # the order while reversals never collide at all.+ # generated column is the one spelling both accept.+ #+ # Null for anything that is not an earning, because null is what a+ # unique index treats as distinct from every other null: earnings+ # collide on their order, and any number of reversals sit alongside+ # them without colliding at all. Deliberately not the row's own id for+ # the other kinds — MySQL refuses a generated column that reads the+ # auto-increment key, which is what CI found.execute <<~SQL.squishALTER TABLE spree_seller_transfersADD COLUMN earning_key BIGINT- AS (CASE WHEN kind = 'earning' THEN order_id ELSE -id END) STORED+ AS (CASE WHEN kind = 'earning' THEN order_id ELSE NULL END) STOREDSQLadd_index :spree_seller_transfers, :earning_key, unique: true,