Created
July 27, 2018 05:51
-
-
Save twe4ked/6fae25b1725752b4aca9d5f802d6e0c6 to your computer and use it in GitHub Desktop.
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
# frozen_string_literal: true | |
class SchemaDump | |
VERSION_REGEX = / | |
^--\sDumped\sfrom\sdatabase\sversion.*$\n | |
^--\sDumped\sby\spg_dump\sversion.*$\n | |
^\n | |
/x | |
def self.call(database_url, filename:) | |
retval = system( | |
'pg_dump', | |
'--schema-only', | |
'--no-owner', | |
'--no-privileges', | |
'--file', | |
filename, | |
database_url, | |
) | |
return unless retval | |
contents = File.read(filename) | |
contents.gsub!(VERSION_REGEX, '') | |
File.open(filename, 'w') { |file| file.puts contents } | |
filename | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment