From 0fadce99134f209bef9c30e8be56768ffbbea90c Mon Sep 17 00:00:00 2001 From: Jeremy Woertink Date: Sun, 18 Aug 2024 13:46:31 -0700 Subject: [PATCH] Use postgres as the default setup db to make things easier for new users. Fixes #1056 --- src/avram.cr | 3 +++ src/avram/migrator/runner.cr | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/avram.cr b/src/avram.cr index 6a79ba4d9..1f15372f5 100644 --- a/src/avram.cr +++ b/src/avram.cr @@ -30,6 +30,9 @@ module Avram setting time_formats : Array(String) = [] of String setting i18n_backend : Avram::I18nBackend = Avram::I18n.new, example: "Avram::I18n.new" setting query_cache_enabled : Bool = false + # This setting is used to connect to postgres before you've setup your app's DB. + # If `postgres` isn't available, you can update to `template1` or some other default DB + setting setup_database_name : String = "postgres" end Log = ::Log.for(Avram) diff --git a/src/avram/migrator/runner.cr b/src/avram/migrator/runner.cr index 816211381..c8eb92b12 100644 --- a/src/avram/migrator/runner.cr +++ b/src/avram/migrator/runner.cr @@ -69,7 +69,7 @@ class Avram::Migrator::Runner end def self.drop_db(quiet? : Bool = false) - DB.connect("#{credentials.connection_string}/#{db_user}") do |db| + DB.connect("#{credentials.connection_string}/#{Avram.settings.setup_database_name}") do |db| db.exec "DROP DATABASE IF EXISTS #{db_name}" end unless quiet? @@ -78,7 +78,7 @@ class Avram::Migrator::Runner end def self.create_db(quiet? : Bool = false) - DB.connect("#{credentials.connection_string}/#{db_user}") do |db| + DB.connect("#{credentials.connection_string}/#{Avram.settings.setup_database_name}") do |db| db.exec "CREATE DATABASE #{db_name}" end unless quiet?