Skip to content

Commit

Permalink
Merge pull request #397 from blackcandy-org/solid_adapters_updates
Browse files Browse the repository at this point in the history
Solid adapters updates
  • Loading branch information
aidewoode authored Nov 7, 2024
2 parents 4482f57 + 8c1653e commit 1812af7
Show file tree
Hide file tree
Showing 19 changed files with 472 additions and 194 deletions.
13 changes: 4 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,16 @@ gem "jsbundling-rails", "~> 1.3.0"
gem "puma", "~> 6.4.0"

# Default database
gem "sqlite3", "~> 1.7.0"

# Enhanced SQLite3 adapter
gem "activerecord-enhancedsqlite3-adapter", "~> 0.7.0"
gem "sqlite3", "~> 2.1.0"

# Cache store
gem "solid_cache", "~> 1.0.0"

# Background job processing
gem "solid_queue", "~> 0.2.1"
gem "solid_queue", "~> 1.0.0"

# Default stack for pub/sub
# Because there is an error while using with Rails 7.2, the fix is not released yet.
# So we use the main branch for now.
gem "litestack", git: "https://github.com/oldmoe/litestack.git", branch: "master"
# Action Cable adapter
gem "solid_cable", "~> 3.0.0"

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem "jbuilder", "~> 2.13.0"
Expand Down
52 changes: 23 additions & 29 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
GIT
remote: https://github.com/oldmoe/litestack.git
revision: 83a1dc5f788bee673a696ca2d6df551a84799bb4
branch: master
specs:
litestack (0.4.4)
erubi (~> 1)
oj (~> 3)
rack (~> 3)
rackup (~> 2)
sqlite3 (>= 1.6.0, < 2.0.0)
tilt (~> 2)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -67,9 +54,6 @@ GEM
activemodel (= 7.2.1)
activesupport (= 7.2.1)
timeout (>= 0.4.0)
activerecord-enhancedsqlite3-adapter (0.7.0)
activerecord (>= 7.1)
sqlite3 (>= 1.6)
activestorage (7.2.1)
actionpack (= 7.2.1)
activejob (= 7.2.1)
Expand Down Expand Up @@ -107,7 +91,7 @@ GEM
bindex (0.8.1)
bootsnap (1.18.4)
msgpack (~> 1.2)
brakeman (6.2.1)
brakeman (6.2.2)
racc
browser (6.0.0)
builder (3.3.0)
Expand Down Expand Up @@ -152,12 +136,17 @@ GEM
rubocop
smart_properties
erubi (1.13.0)
et-orbi (1.2.11)
tzinfo
ferrum (0.13)
addressable (~> 2.5)
concurrent-ruby (~> 1.1)
webrick (~> 1.7)
websocket-driver (>= 0.6, < 0.8)
ffi (1.16.3)
fugit (1.11.1)
et-orbi (~> 1, >= 1.2.11)
raabro (~> 1.4)
globalid (1.2.1)
activesupport (>= 6.1)
hashdiff (1.1.0)
Expand Down Expand Up @@ -234,10 +223,6 @@ GEM
nokogiri (1.16.7)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
oj (3.16.6)
bigdecimal (>= 3.0)
ostruct (>= 0.2)
ostruct (0.6.0)
pagy (6.0.4)
parallel (1.25.1)
parser (3.3.1.0)
Expand All @@ -254,6 +239,7 @@ GEM
public_suffix (5.0.5)
puma (6.4.3)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.8.1)
rack (3.1.7)
rack-session (2.0.0)
Expand Down Expand Up @@ -340,13 +326,23 @@ GEM
simplecov-lcov (0.8.0)
simplecov_json_formatter (0.1.4)
smart_properties (1.17.0)
solid_cable (3.0.2)
actioncable (>= 7.2)
activejob (>= 7.2)
activerecord (>= 7.2)
railties (>= 7.2)
solid_cache (1.0.6)
activejob (>= 7.2)
activerecord (>= 7.2)
railties (>= 7.2)
solid_queue (0.2.2)
rails (~> 7.1)
sqlite3 (1.7.3)
solid_queue (1.0.0)
activejob (>= 7.1)
activerecord (>= 7.1)
concurrent-ruby (>= 1.3.1)
fugit (~> 1.11.0)
railties (>= 7.1)
thor (~> 1.3.1)
sqlite3 (2.1.0)
mini_portile2 (~> 2.8.0)
sshkit (1.22.2)
base64
Expand All @@ -365,7 +361,6 @@ GEM
railties (>= 6.0.0)
stringio (3.1.1)
thor (1.3.2)
tilt (2.4.0)
timeout (0.4.1)
turbo-rails (1.5.0)
actionpack (>= 6.0.0)
Expand Down Expand Up @@ -398,7 +393,6 @@ PLATFORMS
ruby

DEPENDENCIES
activerecord-enhancedsqlite3-adapter (~> 0.7.0)
acts_as_list (~> 1.2.0)
bcrypt (~> 3.1.11)
bootsnap (~> 1.18.0)
Expand All @@ -417,7 +411,6 @@ DEPENDENCIES
jsbundling-rails (~> 1.3.0)
kamal (~> 1.4.0)
listen (~> 3.9.0)
litestack!
memory_profiler (~> 0.9.13)
pagy (~> 6.0.0)
parallel (~> 1.25.0)
Expand All @@ -428,9 +421,10 @@ DEPENDENCIES
ransack (~> 4.2.0)
simplecov (~> 0.22.0)
simplecov-lcov (~> 0.8.0)
solid_cable (~> 3.0.0)
solid_cache (~> 1.0.0)
solid_queue (~> 0.2.1)
sqlite3 (~> 1.7.0)
solid_queue (~> 1.0.0)
sqlite3 (~> 2.1.0)
standard (~> 1.25.0)
standard-rails
stimulus-rails (~> 1.3.4)
Expand Down
6 changes: 6 additions & 0 deletions bin/jobs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env ruby

require_relative "../config/environment"
require "solid_queue/cli"

SolidQueue::Cli.start(ARGV)
10 changes: 7 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ module BlackCandy
include BlackCandy::Configurable

has_config :db_url
has_config :cache_db_url
has_config :cable_db_url
has_config :queue_db_url
has_config :media_path
has_config :db_adapter, default: "sqlite"
has_config :nginx_sendfile, default: false
Expand All @@ -39,8 +42,10 @@ module BlackCandy
raise_config_validation_error "Unsupported database adapter."
end

if value == "postgresql" && ENV["RAILS_ENV"] == "production" && config.db_url.blank?
raise_config_validation_error "DB_URL is required if database adapter is postgresql"
if value == "postgresql" &&
ENV["RAILS_ENV"] == "production" &&
(config.db_url.blank? || config.cache_db_url.blank? || config.cable_db_url.blank? || config.queue_db_url.blank?)
raise_config_validation_error "DB_URL, CABLE_DB_URL, QUEUE_DB_URL and CACHE_DB_URL are required if database adapter is postgresql"
end
end

Expand All @@ -57,7 +62,6 @@ class Application < Rails::Application

config.active_storage.resolve_model_to_route = :rails_storage_proxy

config.solid_queue.silence_polling = true
config.solid_queue.preserve_finished_jobs = false

# Configuration for the application, engines, and railties goes here.
Expand Down
26 changes: 10 additions & 16 deletions config/cable.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
sqlite_default: &sqlite_default
adapter: litecable
default: &default
adapter: solid_cable
connects_to:
database:
writing: cable
polling_interval: 0.1.seconds
message_retention: 1.day

pg_default: &pg_default
adapter: postgresql
development:
<<: *default

test:
adapter: test

<% if BlackCandy.config.db_adapter == "postgresql" %>
development:
<<: *pg_default

production:
<<: *pg_default
<% else %>
development:
<<: *sqlite_default

production:
<<: *sqlite_default
<% end %>
<<: *default
16 changes: 16 additions & 0 deletions config/cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
default: &default
database: cache
store_options:
# Cap age of oldest cache entry to fulfill retention policies
# max_age: <%= 60.days.to_i %>
max_size: <%= 256.megabytes %>
namespace: <%= Rails.env %>

development:
<<: *default

test:
<<: *default

production:
<<: *default
115 changes: 97 additions & 18 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ sqlite_default: &sqlite_default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
default_transaction_mode: immediate

pg_default: &pg_default
adapter: postgresql
Expand All @@ -11,32 +12,110 @@ pg_default: &pg_default

<% if BlackCandy.config.db_adapter == "postgresql" %>
development:
<<: *pg_default
username: <%= ENV['DB_USERNAME'] %>
password: <%= ENV['DB_PASSWORD'] %>
database: blackcandy_development
host: localhost
primary: &primary_development
<<: *pg_default
username: <%= ENV['DB_USERNAME'] %>
password: <%= ENV['DB_PASSWORD'] %>
database: blackcandy_development
host: localhost
cache:
<<: *primary_development
database: blackcandy_development_cache
migrations_paths: db/cache_migrate
cable:
<<: *primary_development
database: blackcandy_development_cable
migrations_paths: db/cable_migrate
queue:
<<: *primary_development
database: blackcandy_development_queue
migrations_paths: db/queue_migrate

test:
<<: *pg_default
username: <%= ENV['DB_USERNAME'] %>
password: <%= ENV['DB_PASSWORD'] %>
database: blackcandy_test
host: localhost
primary: &primary_test
<<: *pg_default
username: <%= ENV['DB_USERNAME'] %>
password: <%= ENV['DB_PASSWORD'] %>
database: blackcandy_test
host: localhost
cache:
<<: *primary_test
database: blackcandy_test_cache
migrations_paths: db/cache_migrate
cable:
<<: *primary_test
database: blackcandy_test_cable
migrations_paths: db/cable_migrate
queue:
<<: *primary_test
database: blackcandy_test_queue
migrations_paths: db/queue_migrate

production:
<<: *pg_default
url: <%= BlackCandy.config.db_url %>
primary: &primary_production
<<: *pg_default
url: <%= BlackCandy.config.db_url %>
cache:
<<: *primary_production
url: <%= BlackCandy.config.cache_db_url %>
migrations_paths: db/cache_migrate
cable:
<<: *primary_production
url: <%= BlackCandy.config.cable_db_url %>
migrations_paths: db/cable_migrate
queue:
<<: *primary_production
url: <%= BlackCandy.config.queue_db_url %>
migrations_paths: db/queue_migrate
<% else %>
development:
<<: *sqlite_default
database: storage/development.sqlite3
primary:
<<: *sqlite_default
database: storage/development.sqlite3
cache:
<<: *sqlite_default
database: storage/development_cache.sqlite3
migrations_paths: db/cache_migrate
cable:
<<: *sqlite_default
database: storage/development_cable.sqlite3
migrations_paths: db/cable_migrate
queue:
<<: *sqlite_default
database: storage/development_queue.sqlite3
migrations_paths: db/queue_migrate

test:
<<: *sqlite_default
database: storage/test.sqlite3
primary:
<<: *sqlite_default
database: storage/test.sqlite3
cache:
<<: *sqlite_default
database: storage/test_cache.sqlite3
migrations_paths: db/cache_migrate
cable:
<<: *sqlite_default
database: storage/test_cable.sqlite3
migrations_paths: db/cable_migrate
queue:
<<: *sqlite_default
database: storage/test_queue.sqlite3
migrations_paths: db/queue_migrate

production:
<<: *sqlite_default
database: storage/production.sqlite3
primary:
<<: *sqlite_default
database: storage/production.sqlite3
cache:
<<: *sqlite_default
database: storage/production_cache.sqlite3
migrations_paths: db/cache_migrate
cable:
<<: *sqlite_default
database: storage/production_cable.sqlite3
migrations_paths: db/cable_migrate
queue:
<<: *sqlite_default
database: storage/production_queue.sqlite3
migrations_paths: db/queue_migrate
<% end %>
1 change: 1 addition & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
config.action_controller.action_on_unpermitted_parameters = :raise

config.active_job.queue_adapter = :solid_queue
config.solid_queue.connects_to = {database: {writing: :queue}}

config.after_initialize do
Bullet.enable = true
Expand Down
Loading

0 comments on commit 1812af7

Please sign in to comment.