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
Fix: run the coupon code and actor type backfills during spree:upgrade (#14692)
Damian Legawiec0da3952c9c9a
diff --git a/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.yml b/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.ymlindex 941b801bda..140fa4d67c 100644--- a/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.yml+++ b/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.yml@@ -438,6 +438,22 @@ steps:once several stores hold tax configuration. The NOT NULL constraints landin 6.1. Idempotent.+ - id: backfill_order_coupon_codes+ name: "Backfill coupon codes on placed orders"+ task: "spree:backfill_order_coupon_codes"+ notes: |+ spree_orders gains a coupon_code column in Spree 6, matching carts.+ Historical placed orders applied coupons only through the promotion+ join tables, so this fills the column from the order's coupon-code+ record, or failing that from the code of an applied single-code+ promotion, so admin filtering and the serializer answer consistently+ for old orders. Reads promotion records only — no dependency on the+ adjustments conversion — and touches completed orders only, so it is+ independent of the cart conversion below. Tune the load size with+ BATCH_SIZE (default 500).++ Idempotent — only orders whose coupon_code is still blank are scanned.+- id: backfill_order_marketsname: "Backfill order markets"task: "spree:backfill_order_markets"@@ -664,6 +680,24 @@ steps:stop the run. Purge the soft-deleted rows later withspree:upgrade:purge_migrated_external_receives.+ - id: backfill_actor_types+ name: "Name the kind of actor on past orders, returns, refunds and receipts"+ task: "spree:upgrade:backfill_actor_types"+ notes: |+ Orders, refunds, returns, exchanges, claims and stock receipts remember+ who cancelled, approved, created or received them. In 6.0 that can be a+ member of staff or an API key, so each actor id column gained a type+ column beside it. Rows written before the upgrade carry an id and no+ type — they could only ever have pointed at an admin user — so this+ fills in the admin user class. Until it runs those rows still read as+ the staff member they always were, with a deprecation warning.++ Run AFTER migrate_returns and migrate_external_receives_to_purchase_orders+ so any actor rows those steps write are covered too. Walks+ every model that declares acted_by, so extensions are included.++ Idempotent — a row that already carries a type is skipped.+- id: recount_stock_levelsname: "Fill in the reserved and incoming counters on every stock level"task: "spree:stock:recount_levels"diff --git a/spree/core/spec/lib/tasks/upgrade_manifests_spec.rb b/spree/core/spec/lib/tasks/upgrade_manifests_spec.rbnew file mode 100644index 0000000000..8ca9dd79c2--- /dev/null+++ b/spree/core/spec/lib/tasks/upgrade_manifests_spec.rb@@ -0,0 +1,53 @@+require 'spec_helper'+require 'rake'++# Guards the contract `rake spree:upgrade` relies on: every manifest step is+# well-formed, ids are unique, and each required step names a rake task that+# spree_core actually defines. A task added without a manifest entry is caught+# by review; an entry pointing at a renamed or missing task is caught here.+describe 'spree:upgrade manifests' do+ manifests = Dir[Spree::Core::Engine.root.join('lib', 'spree', 'upgrades', '*', 'manifest.yml')].sort++ # Load core's rake files into a throwaway application so tasks other specs+ # load individually don't get their actions registered twice.+ let(:rake_app) do+ original = Rake.application+ Rake.application = Rake::Application.new+ Rake::Task.define_task(:environment)+ Dir[Spree::Core::Engine.root.join('lib', 'tasks', '*.rake')].sort.each { |file| load file }+ Rake.application+ ensure+ Rake.application = original+ end++ it 'finds the manifests' do+ expect(manifests).not_to be_empty+ end++ manifests.each do |path|+ context File.basename(File.dirname(path)) do+ let(:manifest) { YAML.safe_load_file(path) }++ it 'gives every step an id, name and task' do+ manifest['steps'].each do |step|+ expect(step).to include('id', 'name', 'task'), "malformed step: #{step.inspect}"+ expect(step.values_at('id', 'name', 'task')).to all(be_a(String).and(match(/\S/))),+ "manifest fields must be non-empty strings: #{step.inspect}"+ end+ end++ it 'has unique step ids' do+ ids = manifest['steps'].map { |step| step['id'] }+ expect(ids).to eq(ids.uniq)+ end++ it 'names a defined rake task for every required step' do+ missing = manifest['steps'].reject { |step| step['optional'] }.+ map { |step| step['task'] }.+ reject { |task| rake_app.lookup(task) }++ expect(missing).to be_empty, "manifest references undefined rake tasks: #{missing.join(', ')}"+ end+ end+ end+end