diff --git a/Gemfile b/Gemfile index 7bf9ad54..5cfceeca 100644 --- a/Gemfile +++ b/Gemfile @@ -34,10 +34,8 @@ gem "solid_cache", "~> 1.0.0" # Background job processing gem "solid_queue", "~> 0.2.1" -# 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" diff --git a/Gemfile.lock b/Gemfile.lock index bb405b79..2e381dee 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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: @@ -234,10 +221,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) @@ -340,6 +323,11 @@ 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) @@ -365,7 +353,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) @@ -417,7 +404,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) @@ -428,6 +414,7 @@ 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) diff --git a/config/application.rb b/config/application.rb index 03ae0c5e..ad250250 100644 --- a/config/application.rb +++ b/config/application.rb @@ -29,6 +29,7 @@ module BlackCandy has_config :db_url has_config :cache_db_url + has_config :cable_db_url has_config :media_path has_config :db_adapter, default: "sqlite" has_config :nginx_sendfile, default: false @@ -42,8 +43,8 @@ module BlackCandy if value == "postgresql" && ENV["RAILS_ENV"] == "production" && - (config.db_url.blank? || config.cache_db_url.blank?) - raise_config_validation_error "DB_URL and CACHE_DB_URL are required if database adapter is postgresql" + (config.db_url.blank? || config.cache_db_url.blank? || config.cable_db_url.blank?) + raise_config_validation_error "DB_URL, CABLE_DB_URL and CACHE_DB_URL are required if database adapter is postgresql" end end diff --git a/config/cable.yml b/config/cable.yml index 31fa8949..4f281a4b 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -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 %> \ No newline at end of file + <<: *default diff --git a/config/database.yml b/config/database.yml index 0d6da86b..df9269c2 100644 --- a/config/database.yml +++ b/config/database.yml @@ -21,6 +21,10 @@ development: <<: *primary_development database: blackcandy_development_cache migrations_paths: db/cache_migrate + cable: + <<: *primary_development + database: blackcandy_development_cable + migrations_paths: db/cable_migrate test: primary: &primary_test @@ -33,6 +37,10 @@ test: <<: *primary_test database: blackcandy_test_cache migrations_paths: db/cache_migrate + cable: + <<: *primary_test + database: blackcandy_test_cable + migrations_paths: db/cable_migrate production: primary: &primary_production @@ -42,6 +50,10 @@ production: <<: *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 <% else %> development: primary: @@ -51,6 +63,10 @@ development: <<: *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 test: primary: @@ -60,6 +76,10 @@ test: <<: *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 production: primary: @@ -69,4 +89,8 @@ production: <<: *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 <% end %> diff --git a/db/cable_schema.rb b/db/cable_schema.rb new file mode 100644 index 00000000..23666604 --- /dev/null +++ b/db/cable_schema.rb @@ -0,0 +1,11 @@ +ActiveRecord::Schema[7.1].define(version: 1) do + create_table "solid_cable_messages", force: :cascade do |t| + t.binary "channel", limit: 1024, null: false + t.binary "payload", limit: 536870912, null: false + t.datetime "created_at", null: false + t.integer "channel_hash", limit: 8, null: false + t.index ["channel"], name: "index_solid_cable_messages_on_channel" + t.index ["channel_hash"], name: "index_solid_cable_messages_on_channel_hash" + t.index ["created_at"], name: "index_solid_cable_messages_on_created_at" + end +end diff --git a/test/lib/black_candy/config_test.rb b/test/lib/black_candy/config_test.rb index 3641a3ec..30b2aaa1 100644 --- a/test/lib/black_candy/config_test.rb +++ b/test/lib/black_candy/config_test.rb @@ -61,7 +61,13 @@ class BlackCandy::ConfigTest < ActiveSupport::TestCase end end - with_env("DB_ADAPTER" => "postgresql", "DB_URL" => "database_url", "CACHE_DB_URL" => "cache_db_url", "RAILS_ENV" => "production") do + with_env( + "DB_ADAPTER" => "postgresql", + "DB_URL" => "database_url", + "CABLE_DB_URL" => "cable_db_url", + "CACHE_DB_URL" => "cache_db_url", + "RAILS_ENV" => "production" + ) do assert_equal "postgresql", BlackCandy.config.db_adapter end end