Skip to content

Instantly share code, notes, and snippets.

@royratcliffe
Created October 2, 2011 14:26
Show Gist options
  • Save royratcliffe/1257499 to your computer and use it in GitHub Desktop.
Save royratcliffe/1257499 to your computer and use it in GitHub Desktop.
Rake task to dump PostgreSQL structure using a compatible pg_dump
namespace :pg do
namespace :structure do
# Does exactly the same as db:structure:dump but with one important
# difference. It tries to use a compatible version of pg_dump. If you see
# the following error message, use pg:structure:dump instead.
#
# pg_dump: server version: 9.1.0; pg_dump version: 9.0.4
# pg_dump: aborting because of server version mismatch
# rake aborted!
# Error dumping database
#
# The pg:structure:dump task overrides the PATH before invoking the regular
# database structure dump. By default it looks for PostgreSQL 9.1 at
# /opt/local/lib/postgresql91 where MacPorts places it. But you can override
# this using POSTGRESQL_PATH on the rake command line.
desc "Dump the PostgreSQL database structure to an SQL file"
task :dump => :environment do
path_to_postgresql = ENV['POSTGRESQL_PATH'] || '/opt/local/lib/postgresql91'
ENV['PATH'] = File.join(path_to_postgresql, 'bin') + ':' + ENV['PATH']
Rake::Task['db:structure:dump'].invoke
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment