Sha256: d81e9aaeaae0331725516dd5a75051baa26c50c00eaf26fee7b93ca0cc4f448b

Contents?: true

Size: 1.21 KB

Versions: 10

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require "shellwords"
require_relative "database"

module Hanami
  module CLI
    module Commands
      module DB
        module Utils
          class Postgres < Database
            def create_command
              system(cli_env_vars, "createdb #{escaped_name}")
            end

            def drop_command
              system(cli_env_vars, "dropdb #{escaped_name}")
            end

            def dump_command
              system(cli_env_vars, "pg_dump --schema-only --no-owner #{escaped_name} > #{dump_file}")
            end

            def load_command
              raise "Not Implemented Yet"
            end

            def escaped_name
              Shellwords.escape(name)
            end

            def cli_env_vars
              @cli_env_vars ||= {}.tap do |vars|
                vars["PGHOST"] = config.host.to_s
                vars["PGPORT"] = config.port.to_s if config.port
                vars["PGUSER"] = config.user.to_s if config.user
                vars["PGPASSWORD"] = config.pass.to_s if config.pass
              end
            end

            def dump_file
              "#{root_path}/db/structure.sql"
            end
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hanami-cli-2.0.0.beta2 lib/hanami/cli/commands/db/utils/postgres.rb
hanami-cli-2.0.0.beta1 lib/hanami/cli/commands/db/utils/postgres.rb
hanami-cli-2.0.0.alpha8.1 lib/hanami/cli/commands/db/utils/postgres.rb
hanami-cli-2.0.0.alpha8 lib/hanami/cli/commands/db/utils/postgres.rb
hanami-cli-2.0.0.alpha7 lib/hanami/cli/commands/db/utils/postgres.rb
hanami-cli-2.0.0.alpha6.1 lib/hanami/cli/commands/db/utils/postgres.rb
hanami-cli-2.0.0.alpha6 lib/hanami/cli/commands/db/utils/postgres.rb
hanami-cli-2.0.0.alpha4 lib/hanami/cli/commands/db/utils/postgres.rb
hanami-cli-2.0.0.alpha3 lib/hanami/cli/commands/db/utils/postgres.rb
hanami-cli-2.0.0.alpha2 lib/hanami/cli/commands/db/utils/postgres.rb