Created
October 2, 2011 14:26
-
-
Save royratcliffe/1257499 to your computer and use it in GitHub Desktop.
Rake task to dump PostgreSQL structure using a compatible pg_dump
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
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