Class: Maintenance::AmazonVariationAbsorption
- Inherits:
-
Object
- Object
- Maintenance::AmazonVariationAbsorption
- Defined in:
- app/services/maintenance/amazon_variation_absorption.rb
Overview
One-shot backfill absorbing every legacy amazon variation (the
legacy_amazon_variations backup table, via LegacyAmazonVariation) into a
VariantGroup amazon override row (catalog = the marketplace's Seller
Central catalog), the listing identity (external_sku/external_id) and
Amazon definition (channel_settings), and re-pointing the junctions:
- catalog_items.variant_group_id <- catalog_items.legacy_amazon_variation_id
- edi_documents.variant_group_id <- edi_documents.legacy_amazon_variation_id
- amazon_browse_nodes_variant_groups <- legacy_amazon_browse_nodes_variations
- clone lineage (cloned_from_id) mapped AV-id -> row-id in a second pass
Variations without a canonical family (variant_group_id nil — families the
Phase 1 backfill couldn't infer) get one created from the variation name.
Idempotent: rows are found by (external_sku, catalog).
Run: Maintenance::AmazonVariationAbsorption.new.call (dry run)
Maintenance::AmazonVariationAbsorption.new(dry_run: false).call
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#call ⇒ Result
Absorbs every legacy amazon variation into a VariantGroup row.
-
#initialize(dry_run: true, io: $stdout) ⇒ AmazonVariationAbsorption
constructor
A new instance of AmazonVariationAbsorption.
Constructor Details
#initialize(dry_run: true, io: $stdout) ⇒ AmazonVariationAbsorption
Returns a new instance of AmazonVariationAbsorption.
30 31 32 33 |
# File 'app/services/maintenance/amazon_variation_absorption.rb', line 30 def initialize(dry_run: true, io: $stdout) @dry_run = dry_run @io = io end |
Instance Method Details
#call ⇒ Result
Absorbs every legacy amazon variation into a VariantGroup row.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/services/maintenance/amazon_variation_absorption.rb', line 37 def call stats = { rows_created: 0, rows_updated: 0, families_created: 0, catalog_items_pointed: 0, edi_documents_pointed: 0, browse_node_links: 0, clone_links: 0, errors: [] } av_to_row = {} LegacyAmazonVariation.includes(:amazon_browse_nodes, :variant_group).find_each(batch_size: 100) do |av| row = absorb_variation(av, stats) av_to_row[av.id] = row&.id rescue StandardError => e stats[:errors] << "AV #{av.id} (#{av.sku}): #{e.}" end link_clone_lineage(av_to_row, stats) unless @dry_run report(stats) Result.new(**stats) end |