Developer Docs - Developer Codex - Normalize Carriage Return Line Feeds

Use the "NormalizeColumnCRLF" helper method against a column name when writing data migrations that have multi line strings. Namely, if the strings are used in a WHERE clause or REPLACE function. It will deal with inconsistencies of CRLFs being changed to LFs when someone edits data.

Example usage:

/// 
/// Fixes the Group Administrator feature's Lava templates that were missed with the original migration
/// due to CRLF issues.
/// 
public void FixGroupAdministratorLavaTemplate()
{
  string lavaTemplate = @"{% if Group.GroupCapacity != null and Group.GroupCapacity != '' %}
  
Capacity
{{ Group.GroupCapacity }}
{% endif %}".Replace( "'", "''" ); string newLavaTemplate = @"{% if Group.GroupCapacity != null and Group.GroupCapacity != '' %}
Capacity
{{ Group.GroupCapacity }}
{% endif %} {% if Group.GroupType.ShowAdministrator and Group.GroupAdministratorPersonAlias != null and Group.GroupAdministratorPersonAlias != '' %} … {% endif %}".Replace( "'", "''" ); // Use NormalizeColumnCRLF when attempting to do a WHERE clause or REPLACE using multi line strings! var targetColumn = RockMigrationHelper.NormalizeColumnCRLF( "GroupViewLavaTemplate" ); Sql( $@" UPDATE [GroupType] SET [GroupViewLavaTemplate] = REPLACE( {targetColumn} ,'{lavaTemplate}' ,'{newLavaTemplate}' ) WHERE {targetColumn} NOT LIKE '%{newLavaTemplate}%'" ); }