Skip to content

Commit

Permalink
FIX: fix normalize_raw method for nil inputs in migration scripts (di…
Browse files Browse the repository at this point in the history
…scourse#22304)

Various migration scripts define a normalize_raw method to do custom processing of post contents before storing it in the Post.raw and other fields.

They normally do not handle nil inputs, but it's a relatively common occurrence in data dumps.

Since this method is used from various points in the migration script, as it stands, the experience of using a migration script is that it will fail multiple times at different points, forcing you to fix the data or apply logic hacks every time then restarting.

This PR generalizes handling of nil input by returning a <missing> string.

Pros:

    no more messy repeated crashes + restarts
    consistency

Cons:

    it might hide data issues
        OTOH we can't print a warning on that method because it will flood the console since it's called from inside loops.

* FIX: zendesk import script: support nil inputs in normalize_raw
* FIX: return '<missing>' instead of empty string; do it for all methods
  • Loading branch information
ldmosquera authored Jun 29, 2023
1 parent f2fe5bc commit c83914e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions script/import_scripts/bespoke_1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ def import_categories
end

def normalize_raw!(raw)
return "<missing>" if raw.blank?

# purple and #1223f3
raw.gsub!(/\[color=[#a-z0-9]+\]/i, "")
raw.gsub!(%r{\[/color\]}i, "")
Expand Down
2 changes: 2 additions & 0 deletions script/import_scripts/jive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ def import_categories
end

def normalize_raw!(raw)
return "<missing>" if raw.blank?

raw = raw.dup
raw = raw[5..-6]

Expand Down
2 changes: 2 additions & 0 deletions script/import_scripts/yammer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ def import_pm_posts
end

def normalize_raw(raw)
return "<missing>" if raw.blank?

raw = raw.gsub('\n', "")
raw.gsub!(/\[\[user:(\d+)\]\]/) do
u = Regexp.last_match(1)
Expand Down
2 changes: 2 additions & 0 deletions script/import_scripts/zendesk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ def import_posts
end

def normalize_raw(raw)
return "<missing>" if raw.blank?

raw = raw.gsub('\n', "")
raw = ReverseMarkdown.convert(raw)
raw
Expand Down
2 changes: 2 additions & 0 deletions script/import_scripts/zendesk_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ def import_likes
end

def normalize_raw(raw, user_id)
return "<missing>" if raw.blank?

raw = raw.gsub('\n', "")
raw = ReverseMarkdown.convert(raw)

Expand Down

0 comments on commit c83914e

Please sign in to comment.