Sha256: ef3f7e6a9684ad675ddac6bb3d4438cc8913fc2da1b9135b1d922148fe5f91e3

Contents?: true

Size: 819 Bytes

Versions: 1

Compression:

Stored size: 819 Bytes

Contents

# NB need to specify a username in the database.yml if you want to use any of these commands
module HerokuTool
  class DbConfiguration
    def config
      db_config_from_file = ERB.new(File.read("config/database.yml")).result
      @config ||= YAML.safe_load(db_config_from_file, [], [], true)
    end

    def generate_drop_tables_sql
      sql = %(select 'DROP TABLE IF EXISTS \\"' || tablename || '\\" CASCADE;' from pg_tables where schemaname = 'public')
      %(psql #{user_arg} #{database} -t -c "#{sql}")
    end

    def user_arg
      username = db_config["username"]
      username.present? && "-U #{username}" || ""
    end

    def database
      db_config["database"]
    end

    private

    def db_config
      config[env]
    end

    def env
      ENV["RAILS_ENV"] || "development"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
heroku_tool-0.4.0 lib/heroku_tool/db_configuration.rb