Class: OnlineMigrations::DataMigrations::UpdateSnowMeltMatArticleUrls

Inherits:
OnlineMigrations::DataMigration
  • Object
show all
Defined in:
lib/online_migrations/data_migrations/update_snow_melt_mat_article_urls.rb

Overview

Update article solution URLs from old snow-melting-mat product line to
the new snowmelt-powermat product line.

Enqueued by: 20251223190000_enqueue_update_snow_melt_mat_article_urls.rb

Replaces in article.solution text:
/products/line/snow-melting-mat -> /products/line/snowmelt-powermat

The old parent "Mat" product line (ID 40, URL snow-melting-mat) has been
split into three sub-product lines: PowerMat, OmniMat, and EcoMat.
PowerMat is the default product for existing references.

Constant Summary collapse

BATCH_SIZE =

Batch size.

100
OLD_URL =

URL for old.

'/products/line/snow-melting-mat'
NEW_URL =

URL for new.

'/products/line/snowmelt-powermat'

Instance Method Summary collapse

Instance Method Details

#collectionObject



24
25
26
# File 'lib/online_migrations/data_migrations/update_snow_melt_mat_article_urls.rb', line 24

def collection
  Article.where('solution ILIKE ?', "%#{OLD_URL}%").in_batches(of: BATCH_SIZE)
end

#countObject



35
36
37
# File 'lib/online_migrations/data_migrations/update_snow_melt_mat_article_urls.rb', line 35

def count
  Article.where('solution ILIKE ?', "%#{OLD_URL}%").count
end

#process(articles) ⇒ Object



28
29
30
31
32
33
# File 'lib/online_migrations/data_migrations/update_snow_melt_mat_article_urls.rb', line 28

def process(articles)
  articles.each do |article|
    new_solution = article.solution.gsub(OLD_URL, NEW_URL)
    article.update_column(:solution, new_solution)
  end
end