Created
June 19, 2024 01:06
-
-
Save akm/799087c7b467431238fb6d0cedb5be1d to your computer and use it in GitHub Desktop.
Remove unnecessary things for draw.io SQL import from mysqldump --no-data
This file contains 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
lines = \ | |
STDIN.readlines.reject{|x| x =~ /\A--/}. | |
reject{|x| x =~ %r{\A\s*/\*.+\*/;\s\z}}. | |
reject{|x| x =~ /\A\s*DROP TABLE.+;\s*\z/}. | |
reject{|x| x =~ /\A\s*UNIQUE KEY .+,\s*\z/}. | |
reject{|x| x =~ /\A\s*KEY .+,\s*\z/}. | |
reject{|x| x =~ /\A\s*CONSTRAINT .+,?\s*\z/} | |
lines = lines.map{|x| x.sub(/\A([^\`]*)\`([^\`]+)\`(.+)/, '\1\2\3') } | |
text = lines.join | |
text.gsub!(/\) ENGINE=InnoDB .+\;/, ")") | |
text.gsub!(/,\n\)/m, "\n)") | |
puts text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment