Skip to content

Commit

Permalink
Add better support for postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
coorasse committed Nov 26, 2024
1 parent 3e9086b commit 74ed11d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on: [push]

env:
RAILS_ENV: test
TARGET_DB: sqlite
PGHOST: localhost
PGUSER: postgres
MOIRAI_GITHUB_REPO_NAME: ${{ secrets.MOIRAI_GITHUB_REPO_NAME }}
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gem "stimulus-rails"
group :development, :test do
gem "puma"
gem "sqlite3"
gem "pg"
gem "rake"
gem "dotenv"
gem "minitest"
Expand Down
8 changes: 7 additions & 1 deletion lib/moirai/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ class Engine < ::Rails::Engine

config.after_initialize do
I18n.original_backend = I18n.backend
if ActiveRecord::Base.connection.data_source_exists?("moirai_translations") || ENV["RAILS_ENV"] == "test"
table_created =
begin
ActiveRecord::Base.connection.table_exists?("moirai_translations")
rescue ActiveRecord::NoDatabaseError
false
end
if table_created
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Moirai.new, I18n.backend)
else
Rails.logger.warn("moirai disabled: tables have not been generated yet.")
Expand Down
26 changes: 13 additions & 13 deletions test/dummy/config/database.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# SQLite. Versions 3.8.0 and up are supported.
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem "sqlite3"
#
<% def database_name_from(name); (ENV["TARGET_DB"] == 'sqlite') ? "db/#{name}.sqlite3" : name; end %>

<% if ENV["TARGET_DB"] == "sqlite" %>
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 50 } %>
timeout: 5000
<% else %>
default: &default
adapter: postgresql
encoding: unicode
pool: 5
<% end %>

development:
<<: *default
database: db/development.sqlite3
database: <%= database_name_from("development") %>

# 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:
<<: *default
database: db/test.sqlite3
database: <%= database_name_from("test") %>

production:
<<: *default
database: db/production.sqlite3
database: <%= database_name_from("production") %>

0 comments on commit 74ed11d

Please sign in to comment.