Sha256: af20538f64e1d1c81998f488b8bae6b24b72a41d40dcec3caef57aae58d313cb

Contents?: true

Size: 1.59 KB

Versions: 5

Compression:

Stored size: 1.59 KB

Contents

module Spontaneous
  module Utils
    module Database
      class PostgresDumper < MySQLDumper
        def initialize(database)
          @database = database
        end

        def name
          "pgsql"
        end

        def load(path)
          system(load_command(path))
        end

        def load_command(path)
          options = [
            "psql",
            "--quiet",
            option(:password),
            option(:username),
            database_name
          ]
          if path =~ /\.gz$/
            options = ["gunzip", "<", path, "|"].concat(options)
          else
            options.concat [ "<", path ]
          end

          options.concat [ ">/dev/null" ]

          command = options.join(" ")
        end

        def dump(path, tables = nil)
          system(dump_command(path, tables))
        end

        def dump_command(path, tables = nil)
          options = [
            "--clean",
            "--no-owner",
            "--no-privileges",
            option(:password),
            option(:username),
            option(:encoding),
            database_name
          ]
          unless tables.nil?
            options.push(tables.join(" "))
          end

          options.push( "| gzip") if path =~ /\.gz$/

          command = %(pg_dump #{options.join(" ")} > #{path} )
        end

        def database_name
          @database.opts[:database]
        end

        def username
          @database.opts[:user]
        end

        def password
          @database.opts[:password]
        end

        def encoding
          "UTF8"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spontaneous-0.2.0.alpha7 lib/spontaneous/utils/database/postgres_dumper.rb
spontaneous-0.2.0.alpha6 lib/spontaneous/utils/database/postgres_dumper.rb
spontaneous-0.2.0.alpha5 lib/spontaneous/utils/database/postgres_dumper.rb
spontaneous-0.2.0.alpha4 lib/spontaneous/utils/database/postgres_dumper.rb
spontaneous-0.2.0.alpha3 lib/spontaneous/utils/database/postgres_dumper.rb