solid_cable 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9a6a47503cbd7f1e11a3ac05879bcf5eafb106f38ed0dc9b02726ba7152cd80
4
- data.tar.gz: f754cc9413be68cdd822d5299f70ff75e6b8d59d26b332a9189a68d50a9bf50f
3
+ metadata.gz: 308be2095ff346a9b56b60f08d26adfabd2c2cfa24dbbf83f7e7df1a0b230b0e
4
+ data.tar.gz: 2875794b63122cb4b11297de037c733d8c91969e1372c1ebfc68dfdf21e7d04d
5
5
  SHA512:
6
- metadata.gz: 9ace1cda46f5899bd5f13b9899ac7704b723291650b09d4a160ab5ecae32180e5240aa4d80355be6472921a01a4e8f45f7ee147a716be8ef2d9c2f1c5666eabb
7
- data.tar.gz: b664e56ffaf4bb2062fe9a3d47c61d452b83a3a437748f9bd1188ac6ee5f83ad7fe2bfd27da77351ab9b59da17bf0b6b3694d0bf0bfe44fa0d01786a970c6b45
6
+ metadata.gz: 113f33268a0056e6233e3c4649f8a1acdbada127439ce47c1784e3c0f733ab7be68223f98b3f624ff7262ea21ec97a8480f52539995430e6f745c2075fca34ad
7
+ data.tar.gz: d153dfb2ac483315464cf2e3d4c870a4524c34ba48298e940511601ca9eae2d1ce07dcad5947426fcf3e4e9db2a694a4b6bd4f12cd854c1208384fa83707d59f
data/README.md CHANGED
@@ -20,19 +20,57 @@ Or install it yourself as:
20
20
  $ gem install solid_cable
21
21
  ```
22
22
 
23
- Now, you need to install the necessary migrations and configure Action Cable's adapter.
23
+ Now, you need to run the installer:
24
24
 
25
25
  ```bash
26
26
  $ bin/rails generate solid_cable:install
27
27
  ```
28
28
 
29
- If you want to install to a different database you can pass an env variable.
30
- ```bash
31
- $ DATABASE=cable bin/rails generate solid_cable:install
29
+ This will create the `db/cable_schema.rb` file.
30
+
31
+ You will then have to add the configuration for the database in `config/database.yml`. If you're using SQLite, it'll look something like this:
32
+
33
+ ```yaml
34
+ production:
35
+ primary:
36
+ <<: *default
37
+ database: storage/production.sqlite3
38
+ cable:
39
+ <<: *default
40
+ database: storage/production_cable.sqlite3
41
+ migrations_paths: db/cable_migrate
42
+ ```
43
+
44
+ ...or if you're using MySQL/PostgreSQL/Trilogy:
45
+
46
+ ```yaml
47
+ production:
48
+ primary: &primary_production
49
+ <<: *default
50
+ database: app_production
51
+ username: app
52
+ password: <%= ENV["APP_DATABASE_PASSWORD"] %>
53
+ cable:
54
+ <<: *primary_production
55
+ database: app_production_cable
56
+ migrations_paths: db/cable_migrate
32
57
  ```
33
58
 
34
- Update `config/cable.yml` to use the new adapter. connects_to is can be omitted
35
- if you want to use the primary database.
59
+ > [!NOTE]
60
+ > Calling `bin/rails generate solid_cable:install` will automatically setup `config/cable.yml`, so no additional configuration is needed there (although you must make sure that you use the `cable` name in `database.yml` for this to match!). But if you want to use Solid Cable in a different environment (like staging or even development), you'll have to manually add that `connects_to` block to the respective environment in the `config/cable.yml` file. And, as always, make sure that the name you're using for the database in `config/cable.yml` matches the name you define in `config/database.yml`.
61
+
62
+ Then run `db:prepare` in production to ensure the database is created and the schema is loaded.
63
+
64
+ ## Usage
65
+
66
+ By default messages are kept around forever. SolidCable ships with a job to
67
+ prune messages. You can run `SolidCable::PruneJob.perform_later` which removes
68
+ Messages that are older than what is specified in `keep_messages_around_for`
69
+ setting.
70
+
71
+ ## Configuration
72
+
73
+ All configuration is managed via the `config/cable.yml`file. To use Solid Cable, the `adapter` value *must be* `solid_cable`. When using Solid Cable, the other values you can set are: `connects_to`, `polling_interval`, `silence_polling`, and `keep_messages_around_for`. For example:
36
74
 
37
75
  ```yaml
38
76
  default: &default
@@ -56,16 +94,5 @@ production:
56
94
  polling_interval: 0.1.seconds
57
95
  ```
58
96
 
59
- Finally, you need to run the migrations:
60
-
61
- ```bash
62
- $ bin/rails db:migrate
63
- ```
64
-
65
- By default messages are kept around forever. SolidCable ships with a job to
66
- prune messages. You can run `SolidCable::PruneJob.perform_later` which removes
67
- Messages that are older than what is specified in `keep_messages_around_for`
68
- setting.
69
-
70
97
  ## License
71
98
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -3,19 +3,36 @@
3
3
  class SolidCable::InstallGenerator < Rails::Generators::Base
4
4
  source_root File.expand_path("templates", __dir__)
5
5
 
6
- class_option :database,
7
- type: :string, aliases: %i(--db),
8
- desc: "The database for your migration. By default, the " \
9
- "current environment's primary database is used."
10
- class_option :skip_migrations, type: :boolean, default: nil,
11
- desc: "Skip migrations"
6
+ def add_solid_errors_db_schema
7
+ template "cable_schema.rb"
8
+ end
9
+
10
+ def configure_production_cable
11
+ gsub_file("config/cable.yml",
12
+ old_production_cable_config,
13
+ new_production_cable_config)
14
+ end
12
15
 
13
- def create_migrations
14
- return if options[:skip_migrations]
16
+ private
15
17
 
16
- db_clause = "DATABASE=#{options[:database]}" if options[:database].present?
18
+ def old_production_cable_config
19
+ <<~YAML
20
+ production:
21
+ adapter: redis
22
+ url: <%%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
23
+ channel_prefix: <%= app_name %>_production
24
+ YAML
25
+ end
17
26
 
18
- rails_command "railties:install:migrations FROM=solid_cable #{db_clause}".strip,
19
- inline: true
27
+ def new_production_cable_config
28
+ <<~YAML
29
+ production:
30
+ adapter: solid_cable
31
+ connects_to:
32
+ database:
33
+ writing: cable
34
+ polling_interval: 0.1.seconds
35
+ keep_messages_around_for: 1.day
36
+ YAML
20
37
  end
21
38
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ ActiveRecord::Schema[7.1].define(version: 1) do
4
+ create_table "solid_cable_messages", force: :cascade do |t|
5
+ t.text "channel"
6
+ t.text "payload"
7
+ t.datetime "created_at", null: false
8
+ t.datetime "updated_at", null: false
9
+ t.index ["channel"], name: "index_solid_cable_messages_on_channel",
10
+ length: 500
11
+ t.index ["created_at"], name: "index_solid_cable_messages_on_created_at"
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidCable
4
+ class Railtie < ::Rails::Railtie
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidCable
4
- VERSION = "1.0.2"
4
+ VERSION = "1.0.4"
5
5
  end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_cable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Pezza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-11 00:00:00.000000000 Z
11
+ date: 2024-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: concurrent-ruby
14
+ name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '7.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rails
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "<"
32
- - !ruby/object:Gem::Version
33
- version: '9'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "<"
39
- - !ruby/object:Gem::Version
40
- version: '9'
26
+ version: '7.2'
41
27
  description: Database-backed Action Cable backend.
42
28
  email:
43
29
  - pezza@hey.com
@@ -51,13 +37,13 @@ files:
51
37
  - app/jobs/solid_cable/prune_job.rb
52
38
  - app/models/solid_cable/message.rb
53
39
  - app/models/solid_cable/record.rb
54
- - db/migrate/20240103034713_create_solid_cable_message.rb
55
- - db/migrate/20240607184711_index_channels.rb
56
40
  - lib/action_cable/subscription_adapter/solid_cable.rb
57
41
  - lib/generators/solid_cable/install/USAGE
58
42
  - lib/generators/solid_cable/install/install_generator.rb
43
+ - lib/generators/solid_cable/install/templates/cable_schema.rb
59
44
  - lib/solid_cable.rb
60
45
  - lib/solid_cable/engine.rb
46
+ - lib/solid_cable/railtie.rb
61
47
  - lib/solid_cable/version.rb
62
48
  homepage: http://github.com/npezza93/solid_cable
63
49
  licenses:
@@ -74,14 +60,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
60
  requirements:
75
61
  - - ">="
76
62
  - !ruby/object:Gem::Version
77
- version: '0'
63
+ version: 3.1.0
78
64
  required_rubygems_version: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - ">="
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
69
  requirements: []
84
- rubygems_version: 3.5.10
70
+ rubygems_version: 3.5.17
85
71
  signing_key:
86
72
  specification_version: 4
87
73
  summary: Database-backed Action Cable backend.
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class CreateSolidCableMessage < ActiveRecord::Migration[7.1]
4
- def change
5
- create_table :solid_cable_messages, if_not_exists: true do |t|
6
- t.text :channel
7
- t.text :payload
8
-
9
- t.timestamps
10
-
11
- t.index :created_at
12
- end
13
- end
14
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class IndexChannels < ActiveRecord::Migration[7.1]
4
- def change
5
- add_index :solid_cable_messages, :channel, length: 500
6
- end
7
- end