Skip to content

Instantly share code, notes, and snippets.

@twe4ked
Created July 27, 2018 05:51
Show Gist options
  • Save twe4ked/6fae25b1725752b4aca9d5f802d6e0c6 to your computer and use it in GitHub Desktop.
Save twe4ked/6fae25b1725752b4aca9d5f802d6e0c6 to your computer and use it in GitHub Desktop.
# 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