Skip to content

Instantly share code, notes, and snippets.

@akm
Created June 19, 2024 01:06
Show Gist options
  • Save akm/799087c7b467431238fb6d0cedb5be1d to your computer and use it in GitHub Desktop.
Save akm/799087c7b467431238fb6d0cedb5be1d to your computer and use it in GitHub Desktop.
Remove unnecessary things for draw.io SQL import from mysqldump --no-data
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