Class: OnlineMigrations::DataMigrations::SplitSharedElectricalSpecRows
- Inherits:
-
OnlineMigrations::DataMigration
- Object
- OnlineMigrations::DataMigration
- OnlineMigrations::DataMigrations::SplitSharedElectricalSpecRows
- Defined in:
- lib/online_migrations/data_migrations/split_shared_electrical_spec_rows.rb
Overview
Walks every existing product_specifications row whose token is in
Models::ItemSpecificationHelper::PER_ITEM_SPEC_TOKENS and clones it
so each item owns its own row. Idempotent: rows already on a single
item are skipped.
Background:
Before the consolidator skip-list landed, the nightly job collapsed
any electrical spec whose value coincided across unrelated items
into a single row. Production today has hundreds of such shared
rows, including five towel-warmer wattage rows shared with unrelated
cable kits. While shared, an edit to one item's wattage rewrites
every co-tenant's value at once.
Constant Summary collapse
- BATCH_SIZE =
Spec rows are heavy on callbacks (translations, render refresh
enqueue), so keep batches small. 25- TOKENS =
Electrical spec tokens whose numeric values coincide across unrelated
SKUs. Stored as strings to match theproduct_specifications.token
column type at query time. Models::ItemSpecificationHelper::PER_ITEM_SPEC_TOKENS.map(&:to_s).freeze
Instance Method Summary collapse
-
#collection ⇒ ActiveRecord::Batches::BatchEnumerator
Yields batches of shared electrical-spec rows.
-
#count ⇒ Integer
Number of shared spec rows queued for splitting.
-
#process(specs) ⇒ void
Splits each spec in the batch into per-item rows.
Instance Method Details
#collection ⇒ ActiveRecord::Batches::BatchEnumerator
Yields batches of shared electrical-spec rows.
37 38 39 |
# File 'lib/online_migrations/data_migrations/split_shared_electrical_spec_rows.rb', line 37 def collection ProductSpecification.where(id: shared_spec_ids).in_batches(of: BATCH_SIZE) end |
#count ⇒ Integer
Number of shared spec rows queued for splitting. Used by
online_migrations for progress reporting.
58 |
# File 'lib/online_migrations/data_migrations/split_shared_electrical_spec_rows.rb', line 58 def count = shared_spec_ids.size |
#process(specs) ⇒ void
This method returns an undefined value.
Splits each spec in the batch into per-item rows. Idempotent: a spec
that already has a single item is a no-op.
49 50 51 |
# File 'lib/online_migrations/data_migrations/split_shared_electrical_spec_rows.rb', line 49 def process(specs) specs.find_each { |spec| split_spec(spec) } end |