From 74bbd45cdf955b8732e1335791583b0926112212 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 21 Jan 2017 07:34:48 +0000 Subject: [PATCH] dotenv: enable overriding database settings. --- app/models/pool_archive.rb | 2 +- app/models/post_archive.rb | 2 +- app/models/post_read_only.rb | 2 +- script/install/database.yml.templ | 13 ++++++++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/models/pool_archive.rb b/app/models/pool_archive.rb index 062fc047b..ff38de4f9 100644 --- a/app/models/pool_archive.rb +++ b/app/models/pool_archive.rb @@ -6,7 +6,7 @@ class PoolArchive < ActiveRecord::Base Danbooru.config.aws_sqs_archives_url.present? end - establish_connection "archive_#{Rails.env}".to_sym if enabled? + establish_connection (ENV["ARCHIVE_DATABASE_URL"] || "archive_#{Rails.env}".to_sym) if enabled? self.table_name = "pool_versions" module SearchMethods diff --git a/app/models/post_archive.rb b/app/models/post_archive.rb index bb1315670..711e51ff1 100644 --- a/app/models/post_archive.rb +++ b/app/models/post_archive.rb @@ -3,7 +3,7 @@ class PostArchive < ActiveRecord::Base Danbooru.config.aws_sqs_archives_url.present? end - establish_connection "archive_#{Rails.env}".to_sym if enabled? + establish_connection (ENV["ARCHIVE_DATABASE_URL"] || "archive_#{Rails.env}".to_sym) if enabled? self.table_name = "post_versions" def self.calculate_version(post_id, updated_at, version_id) diff --git a/app/models/post_read_only.rb b/app/models/post_read_only.rb index 3307e8472..96d0a1f3d 100644 --- a/app/models/post_read_only.rb +++ b/app/models/post_read_only.rb @@ -1,5 +1,5 @@ class PostReadOnly < Post - establish_connection "ro_#{Rails.env}".to_sym + establish_connection (ENV["RO_DATABASE_URL"] || "ro_#{Rails.env}".to_sym) attr_readonly *column_names def with_timeout(n, default_value = nil) diff --git a/script/install/database.yml.templ b/script/install/database.yml.templ index 91e7e4312..5caf077ef 100755 --- a/script/install/database.yml.templ +++ b/script/install/database.yml.templ @@ -5,6 +5,7 @@ development: database: danbooru2 pool: 5 timeout: 5000 + url: <%= ENV['DATABASE_URL'] %> # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". @@ -14,42 +15,52 @@ test: database: danbooru2_test pool: 5 timeout: 5000 + url: <%= ENV['DATABASE_URL'] %> production: adapter: postgresql database: danbooru2 pool: 5 timeout: 5000 + url: <%= ENV['DATABASE_URL'] %> # read only databases, just point to local copies if you have no need ro_development: adapter: postgresql database: danbooru2 + url: <%= ENV['RO_DATABASE_URL'] %> ro_test: adapter: postgresql database: danbooru2_test + url: <%= ENV['RO_DATABASE_URL'] %> ro_production: adapter: postgresql database: danbooru2 + url: <%= ENV['RO_DATABASE_URL'] %> ro_staging: adapter: postgresql database: danbooru2 + url: <%= ENV['RO_DATABASE_URL'] %> archive_development: adapter: postgresql database: archive_development + url: <%= ENV['ARCHIVE_DATABASE_URL'] %> archive_test: adapter: postgresql database: archive_test + url: <%= ENV['ARCHIVE_DATABASE_URL'] %> archive_production: adapter: postgresql database: archive_development + url: <%= ENV['ARCHIVE_DATABASE_URL'] %> archive_staging: adapter: postgresql - database: archive_development \ No newline at end of file + database: archive_development + url: <%= ENV['ARCHIVE_DATABASE_URL'] %>