From 189adc683f9b3c2c5784c7a9245dd4abb0edf401 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 23 Mar 2021 02:29:45 -0500 Subject: [PATCH] config: set default database connection settings. Set sensible defaults for connecting to the database. By default, we try to connect to the `danbooru2` database running on localhost as the `danbooru` user. These are the defaults recommended by the install guide. If you need to change the database settings, set DATABASE_URL in .env.local or on the command line: # .env.local DATABASE_URL=postgresql://danbooru:password@localhost/danbooru2 # command line $ DATABASE_URL=postgresql://danbooru:password@localhost/danbooru2 bin/rails server This eliminates the need to copy script/install/database.yml.templ to config/database.yml during installation and during deployment. This is so that Danbooru works out of the box without extra configuration. In particular, this is so that we can run Danbooru in a Docker container without having to set DATABASE_URL. --- .gitignore | 1 - INSTALL.debian | 1 - config/database.yml | 39 +++++++++++++++++++++++++++ lib/capistrano/tasks/symlink.rake | 1 - script/install/database.yml.templ | 45 ------------------------------- 5 files changed, 39 insertions(+), 48 deletions(-) create mode 100644 config/database.yml delete mode 100644 script/install/database.yml.templ diff --git a/.gitignore b/.gitignore index 68388e02e..4b2ee4fda 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ .yarn-integrity .gitconfig .git/ -config/database.yml config/danbooru_local_config.rb config/deploy/*.rb config/newrelic.yml diff --git a/INSTALL.debian b/INSTALL.debian index a471b1eeb..41c99c4bb 100644 --- a/INSTALL.debian +++ b/INSTALL.debian @@ -139,7 +139,6 @@ mkdir -p /var/www/danbooru2/shared/data mkdir -p /var/www/danbooru2/shared/data/preview mkdir -p /var/www/danbooru2/shared/data/sample chown -R danbooru:danbooru /var/www/danbooru2 -curl -L -s $GITHUB_INSTALL_SCRIPTS/database.yml.templ -o /var/www/danbooru2/shared/config/database.yml curl -L -s $GITHUB_INSTALL_SCRIPTS/danbooru_local_config.rb.templ -o /var/www/danbooru2/shared/config/danbooru_local_config.rb echo "* Almost done! You are now ready to deploy Danbooru onto this server." diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 000000000..4f119bfd4 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,39 @@ +# Don't edit this file. To override this file, set `DATABASE_URL` in .env.local +# instead. Example: +# +# DATABASE_URL=postgresql://danbooru:password@localhost/danbooru2 +# +# https://guides.rubyonrails.org/configuring.html#configuring-a-database + +default: &default + adapter: postgresql + username: danbooru + host: localhost + url: <%= ENV["DATABASE_URL"] %> + +production: + <<: *default + database: danbooru2 + +development: + <<: *default + database: danbooru2 + +test: + <<: *default + database: danbooru2_test + +archive_production: + <<: *default + database: archive_production + url: <%= ENV["ARCHIVE_DATABASE_URL"] %> + +archive_development: + <<: *default + database: archive_development + url: <%= ENV["ARCHIVE_DATABASE_URL"] %> + +archive_test: + <<: *default + database: archive_test + url: <%= ENV["ARCHIVE_DATABASE_URL"] %> diff --git a/lib/capistrano/tasks/symlink.rake b/lib/capistrano/tasks/symlink.rake index c646a6225..ad737957f 100644 --- a/lib/capistrano/tasks/symlink.rake +++ b/lib/capistrano/tasks/symlink.rake @@ -3,7 +3,6 @@ namespace :symlink do task :local_files do on roles(:app, :worker) do execute :ln, "-s", "#{deploy_to}/shared/config/danbooru_local_config.rb", "#{release_path}/config/danbooru_local_config.rb" - execute :ln, "-s", "#{deploy_to}/shared/config/database.yml", "#{release_path}/config/database.yml" if test("[ -f #{deploy_to}/shared/config/newrelic.yml ]") execute :ln, "-s", "#{deploy_to}/shared/config/newrelic.yml", "#{release_path}/config/newrelic.yml" end diff --git a/script/install/database.yml.templ b/script/install/database.yml.templ deleted file mode 100644 index fb4795943..000000000 --- a/script/install/database.yml.templ +++ /dev/null @@ -1,45 +0,0 @@ -# SQLite version 3.x -# gem install sqlite3-ruby (not necessary on OS X Leopard) -development: - adapter: postgresql - 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". -# Do not set this db to the same as development or production. -test: - adapter: postgresql - database: danbooru2_test - pool: 5 - timeout: 5000 - url: <%= ENV['DATABASE_URL'] %> - -production: - adapter: postgresql - database: danbooru2 - pool: 5 - timeout: 5000 - url: <%= ENV['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 - url: <%= ENV['ARCHIVE_DATABASE_URL'] %>