├── Gemfile ├── MIT-LICENSE ├── README.md ├── Rakefile ├── heroku-sql-console.gemspec ├── init.rb └── lib ├── heroku-sql-console.rb ├── heroku-sql-console └── version.rb └── heroku └── command └── sql.rb /Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | 3 | # Specify your gem's dependencies in heroku-sql-console.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010, David Dollar, Terence Lee 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deprecated 2 | 3 | This project is deprecated and is no longer being maintained. 4 | 5 | Please check out my current project [Convox](https://convox.com) for all of your deployment needs! 6 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler' 2 | Bundler::GemHelper.install_tasks 3 | -------------------------------------------------------------------------------- /heroku-sql-console.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | $:.push File.expand_path("../lib", __FILE__) 3 | require "heroku-sql-console/version" 4 | 5 | Gem::Specification.new do |s| 6 | s.name = "heroku-sql-console" 7 | s.version = Heroku::Command::Sql::VERSION 8 | s.platform = Gem::Platform::RUBY 9 | s.authors = ["David Dollar", "Terence Lee"] 10 | s.email = ["ddollar@gmail.com", "hone02@gmail.com"] 11 | s.homepage = "" 12 | s.summary = %q{Plugin that provides a sql console for your heroku app.} 13 | s.description = %q{Plugin that provides a sql console for your heroku app. } 14 | 15 | s.rubyforge_project = "heroku-sql-console" 16 | 17 | s.files = `git ls-files`.split("\n") 18 | s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") 19 | s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } 20 | s.require_paths = ["lib"] 21 | 22 | s.add_dependency "heroku", "~> 2.0.0" 23 | end 24 | -------------------------------------------------------------------------------- /init.rb: -------------------------------------------------------------------------------- 1 | require 'heroku-sql-console' 2 | -------------------------------------------------------------------------------- /lib/heroku-sql-console.rb: -------------------------------------------------------------------------------- 1 | require 'heroku/command/sql' 2 | require 'heroku-sql-console/version' 3 | -------------------------------------------------------------------------------- /lib/heroku-sql-console/version.rb: -------------------------------------------------------------------------------- 1 | module Heroku 2 | module Command 3 | class Sql 4 | VERSION = "0.0.1" 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/heroku/command/sql.rb: -------------------------------------------------------------------------------- 1 | # SQL console like for your heroku app's database 2 | class Heroku::Command::Sql < Heroku::Command::BaseWithApp 3 | 4 | # sql 5 | # 6 | # access the sql console for your datasabe 7 | # 8 | def index 9 | database_url = heroku.config_vars(app)['DATABASE_URL'] 10 | 11 | sqlconsole_history_read(app) 12 | 13 | display "SQL console for #{app}.#{heroku.host}" 14 | while sql = Readline.readline('SQL> ') 15 | unless sql.nil? || sql.strip.empty? 16 | sqlconsole_history_add(app, sql) 17 | break if sql.downcase.strip == 'exit' 18 | display execute_sql(database_url, sql) 19 | end 20 | end 21 | end 22 | 23 | private 24 | def resource 25 | @resource ||= RestClient::Resource.new("https://sql-console.heroku.com") 26 | end 27 | 28 | def execute_sql(database_url, sql) 29 | resource["/query"].post(:database_url => database_url, :sql => sql) 30 | rescue RestClient::InternalServerError 31 | display "An error has occurred." 32 | end 33 | 34 | def sqlconsole_history_dir 35 | FileUtils.mkdir_p(path = "#{home_directory}/.heroku/sqlconsole_history") 36 | path 37 | end 38 | 39 | def sqlconsole_history_file(app) 40 | "#{sqlconsole_history_dir}/#{app}" 41 | end 42 | 43 | def sqlconsole_history_read(app) 44 | history = File.read(sqlconsole_history_file(app)).split("\n") 45 | if history.size > 50 46 | history = history[(history.size - 51),(history.size - 1)] 47 | File.open(sqlconsole_history_file(app), "w") { |f| f.puts history.join("\n") } 48 | end 49 | history.each { |cmd| Readline::HISTORY.push(cmd) } 50 | rescue Errno::ENOENT 51 | end 52 | 53 | def sqlconsole_history_add(app, sql) 54 | Readline::HISTORY.push(sql) 55 | File.open(sqlconsole_history_file(app), "a") { |f| f.puts sql + "\n" } 56 | end 57 | 58 | end 59 | --------------------------------------------------------------------------------