Commit e1755d7e645dcdc40bc5f4ff1eeff97c6d0e67ff
Exists in
master
and in
17 other branches
Merge branch 'allow_erb_template_in_database_yml' into 'master'
allows erb templates in_database.yml This MR will allows us to do use erb templating syntax inside config/database.yml Example: <code> <% # http://mislav.uniqpath.com/rails/branching-the-database-along-with-your-code/ app = "noosfero" branch = `git symbolic-ref HEAD 2>/dev/null`.chomp.sub('refs/heads/', '') user = (`whoami`).gsub(/\W/, '') %> development: adapter: postgresql encoding: unicode database: <%= "#{app}_#{branch}_development" %> template: template0 username: <%= user %> password: </code> Did not break any test that was passing before: Before: https://travis-ci.org/noosfero/noosfero/builds/99440879 After: https://travis-ci.org/evandrojr/noosferogov/jobs/99462155 See merge request !755
Showing
3 changed files
with
6 additions
and
4 deletions
Show diff stats
lib/noosfero/multi_tenancy.rb
... | ... | @@ -26,7 +26,7 @@ module Noosfero |
26 | 26 | |
27 | 27 | def self.load_map |
28 | 28 | db_file = Rails.root.join('config', 'database.yml') |
29 | - db_config = YAML.load_file(db_file) | |
29 | + db_config = YAML.load(ERB.new(File.read(db_file)).result) | |
30 | 30 | map = { } |
31 | 31 | db_config.each do |env, attr| |
32 | 32 | next unless env.match(/_#{Rails.env}$/) and attr['adapter'] =~ /^postgresql$/i |
... | ... | @@ -37,7 +37,7 @@ module Noosfero |
37 | 37 | |
38 | 38 | def self.is_hosted_environment? |
39 | 39 | db_file = Rails.root.join('config', 'database.yml') |
40 | - db_config = YAML.load_file(db_file) | |
40 | + db_config = YAML.load(ERB.new(File.read(db_file)).result) | |
41 | 41 | db_config.select{ |env, attr| Rails.env.to_s.match(/_#{env}$/) }.any? |
42 | 42 | end |
43 | 43 | ... | ... |
lib/tasks/backup.rake
script/odbcconf
1 | 1 | #!/usr/bin/env ruby |
2 | 2 | |
3 | 3 | require 'yaml' |
4 | -config = YAML.load_file(File.dirname(__FILE__) + '/../config/database.yml')['production'] | |
4 | +require 'erb' | |
5 | 5 | |
6 | +config = YAML.load(ERB.new(File.read(File.dirname(__FILE__) + '/../config/database.yml')).result)['production'] | |
6 | 7 | |
7 | 8 | puts "[PostgreSQLEjabberdNoosfero]" |
8 | 9 | puts "Description = PostgreSQL Noosfero ejabberd database" | ... | ... |