Move db check to the Fizzy module

This commit is contained in:
Jorge Manrubia
2025-11-23 04:32:22 +01:00
committed by Jorge Manrubia
parent 6134407f5e
commit bab914d4e0
2 changed files with 27 additions and 9 deletions
+3 -6
View File
@@ -1,7 +1,4 @@
<% <%
database_adapter = ENV.fetch("DATABASE_ADAPTER", "mysql")
use_sqlite = database_adapter == "sqlite"
if ENV["MIGRATE"].present? if ENV["MIGRATE"].present?
mysql_app_user_key = "MYSQL_ALTER_USER" mysql_app_user_key = "MYSQL_ALTER_USER"
mysql_app_password_key = "MYSQL_ALTER_PASSWORD" mysql_app_password_key = "MYSQL_ALTER_PASSWORD"
@@ -17,7 +14,7 @@
%> %>
default: &default default: &default
<% if use_sqlite %> <% if Fizzy.db_adapter.sqlite? %>
adapter: sqlite3 adapter: sqlite3
pool: 5 pool: 5
timeout: 5000 timeout: 5000
@@ -33,7 +30,7 @@ default: &default
<% end %> <% end %>
development: development:
<% if use_sqlite %> <% if Fizzy.db_adapter.sqlite? %>
primary: primary:
<<: *default <<: *default
database: storage/development.sqlite3 database: storage/development.sqlite3
@@ -69,7 +66,7 @@ development:
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production. # Do not set this db to the same as development or production.
test: test:
<% if use_sqlite %> <% if Fizzy.db_adapter.sqlite? %>
primary: primary:
<<: *default <<: *default
database: storage/test.sqlite3 database: storage/test.sqlite3
+24 -3
View File
@@ -1,6 +1,27 @@
module Fizzy module Fizzy
def self.saas? class << self
return @saas if defined?(@saas) def saas?
@saas = !!(ENV["SAAS"] || File.exist?(File.expand_path("../../tmp/saas.txt", __dir__))) return @saas if defined?(@saas)
@saas = !!(ENV["SAAS"] || File.exist?(File.expand_path("../../tmp/saas.txt", __dir__)))
end
def db_adapter
@db_adapter ||= DbAdapter.new ENV.fetch("DATABASE_ADAPTER", saas? ? "mysql" : "sqlite")
end
end
class DbAdapter
def initialize(name)
@name = name.to_s
end
def to_s
@name
end
# Not using inquiry so that it works before Rails env loads.
def sqlite?
@name == "sqlite"
end
end end
end end