Sha256: 17fdb7496b1d7f99700dea206a1aa9b93f0211d76f3d38cd3db91f0a2268b092

Contents?: true

Size: 931 Bytes

Versions: 2

Compression:

Stored size: 931 Bytes

Contents

# frozen_string_literal: true

class Combustion::Databases::PostgreSQL < Combustion::Databases::Base
  def reset
    base.clear_active_connections!
    establish_connection(postgres_configuration)

    super
  end

  private

  def create
    connection.create_database(
      configuration["database"],
      configuration.merge("encoding" => encoding)
    )
  rescue StandardError => error
    $stderr.puts error, *error.backtrace
    $stderr.puts "Couldn't create database for #{configuration.inspect}"
  end

  def drop
    connection.drop_database(configuration["database"])
  end

  def encoding
    configuration["encoding"] || ENV["CHARSET"] || "utf8"
  end

  def postgres_configuration
    configuration.merge(
      "database"           => "postgres",
      "schema_search_path" => schema_search_path
    )
  end

  def schema_search_path
    configuration["adapter"][/postgis/] ? "public, postgis" : "public"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
combustion-0.9.0 lib/combustion/databases/postgresql.rb
combustion-0.8.0 lib/combustion/databases/postgresql.rb