Last active
July 6, 2025 21:05
-
-
Save kch/75b93a6ff2000cbcff38bd29f9f5f7cc to your computer and use it in GitHub Desktop.
Clean trailing newlines and spaces from structure.sql after dumping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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