Skip to content

Instantly share code, notes, and snippets.

@shunchu
Forked from royratcliffe/pg.rake
Created July 8, 2012 10:25
Show Gist options
  • Select an option

  • Save shunchu/3070392 to your computer and use it in GitHub Desktop.

Select an option

Save shunchu/3070392 to your computer and use it in GitHub Desktop.

Revisions

  1. Roy Ratcliffe created this gist Oct 2, 2011.
    23 changes: 23 additions & 0 deletions pg.rake
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    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