Sha256: 5ceec580c276564572d924f4e3ccf9ad0146f69870ba96084997de638df93560

Contents?: true

Size: 1.7 KB

Versions: 9

Compression:

Stored size: 1.7 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),
            option(:exclude_table),
            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

        def exclude_table
          revision_archive_table
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta9 lib/spontaneous/utils/database/postgres_dumper.rb
spontaneous-0.2.0.beta8 lib/spontaneous/utils/database/postgres_dumper.rb
spontaneous-0.2.0.beta7 lib/spontaneous/utils/database/postgres_dumper.rb
spontaneous-0.2.0.beta6 lib/spontaneous/utils/database/postgres_dumper.rb
spontaneous-0.2.0.beta5 lib/spontaneous/utils/database/postgres_dumper.rb
spontaneous-0.2.0.beta4 lib/spontaneous/utils/database/postgres_dumper.rb
spontaneous-0.2.0.beta3 lib/spontaneous/utils/database/postgres_dumper.rb
spontaneous-0.2.0.beta2 lib/spontaneous/utils/database/postgres_dumper.rb
spontaneous-0.2.0.beta1 lib/spontaneous/utils/database/postgres_dumper.rb