heroku_db_env 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.md +72 -0
- data/Rakefile +3 -0
- data/heroku_db_env.gemspec +24 -0
- data/lib/heroku_db_env/railtie.rb +51 -0
- data/lib/heroku_db_env/version.rb +3 -0
- data/lib/heroku_db_env.rb +1 -0
- metadata +54 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
## Features
|
2
|
+
|
3
|
+
* Overwrite Heroku's auto generated database configuration
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add the gem to your gemfile
|
8
|
+
|
9
|
+
gem 'heroku_db_env'
|
10
|
+
|
11
|
+
Add your custom database configuation or overrides to the heroku_database.yml
|
12
|
+
file. The format is identical to database.yml. The gem will also look for any
|
13
|
+
environment variables in the format [env]_DATABASE_URL and merge the resulting
|
14
|
+
connection hash into the database configuation.
|
15
|
+
|
16
|
+
## Example
|
17
|
+
|
18
|
+
Lets assume that you are running in your production environment and your
|
19
|
+
DATABASE_URL is set to
|
20
|
+
|
21
|
+
postgres://user:pass@hostname/db_prod
|
22
|
+
|
23
|
+
Heroku's auto-generated database.yml is actually an ERB script which will
|
24
|
+
transform the DATABASE_URL environment variable to the following connection
|
25
|
+
config when the file is read
|
26
|
+
|
27
|
+
production:
|
28
|
+
adapter: postgres
|
29
|
+
database: db_prod
|
30
|
+
username: user
|
31
|
+
password: pass
|
32
|
+
host: hostname
|
33
|
+
|
34
|
+
Now lets say, for whatever reason, you are unhappy with the auto generated
|
35
|
+
database configuration. You can overwrite it by providing a heroku_database.yml
|
36
|
+
file in your config directory and/or by specifying environment specific
|
37
|
+
DATABASE_URL env vars.
|
38
|
+
|
39
|
+
In your heroku_database.yml
|
40
|
+
|
41
|
+
production:
|
42
|
+
pool: 10
|
43
|
+
|
44
|
+
reporting:
|
45
|
+
pool: 5
|
46
|
+
schema_search_path: reporting_schema
|
47
|
+
|
48
|
+
And your REPORTING_DATABASE_URL is set to
|
49
|
+
|
50
|
+
postgres://user:pass@reporting.hostname/db_reporting
|
51
|
+
|
52
|
+
The final database configuration should look like
|
53
|
+
|
54
|
+
production:
|
55
|
+
adapter: postgres
|
56
|
+
database: db_prod
|
57
|
+
username: user
|
58
|
+
password: pass
|
59
|
+
host: hostname
|
60
|
+
pool: 10
|
61
|
+
reporting:
|
62
|
+
adapter: postgres
|
63
|
+
database: db_reporting
|
64
|
+
username: user
|
65
|
+
password: pass
|
66
|
+
host: reporting.hostname
|
67
|
+
pool: 5
|
68
|
+
schema_search_path: reporting_schema
|
69
|
+
|
70
|
+
Run a db rake task against any configured database to test the setup
|
71
|
+
|
72
|
+
rake db:migrate RAILS_ENV=reporting
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "heroku_db_env/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "heroku_db_env"
|
7
|
+
s.version = HerokuDbEnv::VERSION
|
8
|
+
s.authors = ["Alex Skryl"]
|
9
|
+
s.email = ["rut216@gmail.com"]
|
10
|
+
s.homepage = "http://github.com/skryl/heroku_db_env"
|
11
|
+
s.summary = %q{Overwrite Heroku's auto generated database.yml configuration}
|
12
|
+
s.description = %q{Use a custom database.yml in a Heroku application}
|
13
|
+
|
14
|
+
s.rubyforge_project = "heroku_db_env"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module HerokuDbEnv
|
2
|
+
DB_URL_MATCHER = /(.*)_DATABASE_URL/
|
3
|
+
|
4
|
+
class HerokuDbEnvRailtie < Rails::Railtie
|
5
|
+
config.before_initialize do |app|
|
6
|
+
db_config = HerokuDbEnv.build_db_config(app.config.database_configuration)
|
7
|
+
|
8
|
+
# force active_record to use the db config instead of the db url
|
9
|
+
ENV['DATABASE_URL'] = nil
|
10
|
+
|
11
|
+
app.config.class_eval do
|
12
|
+
define_method(:database_configuration) { db_config }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
class << self
|
19
|
+
|
20
|
+
def build_db_config(default_config = {})
|
21
|
+
heroku_config = load_heroku_db_config(Rails.root.join('config/heroku_database.yml'))
|
22
|
+
overlay_configs(default_config, heroku_config, env_config)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def load_heroku_db_config(db_yml)
|
28
|
+
return {} unless File.exists?(db_yml)
|
29
|
+
require 'erb'
|
30
|
+
YAML::load(ERB.new(IO.read(db_yml)).result)
|
31
|
+
end
|
32
|
+
|
33
|
+
def env_config
|
34
|
+
db_env.inject({}) do |a, (env, config)|
|
35
|
+
resolver = ActiveRecord::Base::ConnectionSpecification::Resolver.new(config, {})
|
36
|
+
a[env.match(DB_URL_MATCHER)[1].downcase] = resolver.spec.config; a
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def db_env
|
41
|
+
ENV.select { |k,v| DB_URL_MATCHER === k }
|
42
|
+
end
|
43
|
+
|
44
|
+
def overlay_configs(*configs)
|
45
|
+
configs.inject({}) do |a, c|
|
46
|
+
a.deep_merge(c.with_indifferent_access)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'heroku_db_env/railtie' if defined?(Rails)
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: heroku_db_env
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alex Skryl
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-08 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Use a custom database.yml in a Heroku application
|
15
|
+
email:
|
16
|
+
- rut216@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- heroku_db_env.gemspec
|
27
|
+
- lib/heroku_db_env.rb
|
28
|
+
- lib/heroku_db_env/railtie.rb
|
29
|
+
- lib/heroku_db_env/version.rb
|
30
|
+
homepage: http://github.com/skryl/heroku_db_env
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project: heroku_db_env
|
50
|
+
rubygems_version: 1.8.15
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: Overwrite Heroku's auto generated database.yml configuration
|
54
|
+
test_files: []
|