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

#collectionActiveRecord::Batches::BatchEnumerator

Returns batches of articles containing the old URL.

Returns:

  • (ActiveRecord::Batches::BatchEnumerator)

    batches of articles containing the old URL



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

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

#countInteger

Returns number of articles containing the old URL.

Returns:

  • (Integer)

    number of articles containing the old URL



38
39
40
# File 'lib/online_migrations/data_migrations/update_snow_melt_mat_article_urls.rb', line 38

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

#process(articles) ⇒ void

This method returns an undefined value.

Returns rewrites the URL per article.



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

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