Skip to content

Instantly share code, notes, and snippets.

@kch
Last active July 6, 2025 21:05
Show Gist options
  • Save kch/75b93a6ff2000cbcff38bd29f9f5f7cc to your computer and use it in GitHub Desktop.
Save kch/75b93a6ff2000cbcff38bd29f9f5f7cc to your computer and use it in GitHub Desktop.
Clean trailing newlines and spaces from structure.sql after dumping
# config/initializers/structure_dump_cleanup.rb
# Clean trailing newlines and spaces from SQL schema dump file after dumping
module StructureDumpWhitespaceCleanup
def structure_dump(cfg, fn, *) = super.tap{ @dump_file = fn }
def dump_schema(...)
super.tap do
next unless fn = @dump_file
File.write fn, File.read(fn).gsub(/[ \t]+\n/, "\n").sub(/\s+\n\z/, "\n")
end
end
end
class << ActiveRecord::Tasks::DatabaseTasks
prepend StructureDumpWhitespaceCleanup
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment