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?
mysql_app_user_key = "MYSQL_ALTER_USER"
mysql_app_password_key = "MYSQL_ALTER_PASSWORD"
@@ -17,7 +14,7 @@
%>
default: &default
<% if use_sqlite %>
<% if Fizzy.db_adapter.sqlite? %>
adapter: sqlite3
pool: 5
timeout: 5000
@@ -33,7 +30,7 @@ default: &default
<% end %>
development:
<% if use_sqlite %>
<% if Fizzy.db_adapter.sqlite? %>
primary:
<<: *default
database: storage/development.sqlite3
@@ -69,7 +66,7 @@ development:
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<% if use_sqlite %>
<% if Fizzy.db_adapter.sqlite? %>
primary:
<<: *default
database: storage/test.sqlite3
+22 -1
View File
@@ -1,6 +1,27 @@
module Fizzy
def self.saas?
class << self
def saas?
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