Skip to content

Commit 353ace9

Browse files
committed
Remove skip_migrations and introduce database and skip_adapter on install
We never want to skip the migrations but we might want to skip setting the adapter if we're moving from another Active Job backend. Also, add a `database` option to select a different DB from the main one when copying the migrations.
1 parent f0981c1 commit 353ace9

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ $ bin/rails generate solid_queue:install
3131

3232
This will set `solid_queue` as the Active Job's adapter in production, and will copy the required migration over to your app.
3333

34-
Alternatively, you can add only the migration to your app:
34+
Alternatively, you can skip setting the Active Job's adapter with:
3535
```bash
36-
$ bin/rails solid_queue:install:migrations
36+
$ bin/rails generate solid_queue:install --skip_adapter
3737
```
3838

3939
And set Solid Queue as your Active Job's queue backend manually, in your environment config:
@@ -42,7 +42,7 @@ And set Solid Queue as your Active Job's queue backend manually, in your environ
4242
config.active_job.queue_adapter = :solid_queue
4343
```
4444

45-
Alternatively, you can set only specific jobs to use Solid Queue as their backend if you're migrating from another adapter and want to move jobs progressively:
45+
Or you can set only specific jobs to use Solid Queue as their backend if you're migrating from another adapter and want to move jobs progressively:
4646

4747
```ruby
4848
# app/jobs/my_job.rb
@@ -194,13 +194,13 @@ development:
194194
# ...
195195
```
196196

197-
Install migrations and specify the dedicated database name with the `DATABASE` option. This will create the Solid Queue migration files in a separate directory, matching the value provided in `migrations_paths` in `config/database.yml`.
197+
Install migrations and specify the dedicated database name with the `--database` option. This will create the Solid Queue migration files in a separate directory, matching the value provided in `migrations_paths` in `config/database.yml`.
198198

199199
```bash
200-
$ bin/rails solid_queue:install:migrations DATABASE=solid_queue
200+
$ bin/rails g solid_queue:install --database solid_queue
201201
```
202202

203-
Note: If you've already run the solid queue install command (`bin/rails generate solid_queue:install`), the migration files will have already been generated under the primary database's `db/migrate/` directory. You can remove these files and keep the ones generated by the database-specific migration installation above.
203+
Note: If you've already run the solid queue install command (`bin/rails generate solid_queue:install`) without a `--database` option, the migration files will have already been generated under the primary database's `db/migrate/` directory. You can remove these files and keep the ones generated by the database-specific migration installation above.
204204

205205
Finally, run the migrations:
206206

lib/generators/solid_queue/install/install_generator.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@
33
class SolidQueue::InstallGenerator < Rails::Generators::Base
44
source_root File.expand_path("templates", __dir__)
55

6-
class_option :skip_migrations, type: :boolean, default: nil, desc: "Skip migrations"
6+
class_option :skip_adapter, type: :boolean, default: nil, desc: "Skip setting Solid Queue as the Active Job's adapter"
7+
class_option :database, type: :string, default: nil, desc: "The database to use for migrations, if different from the primary one."
78

89
def add_solid_queue
9-
if (env_config = Pathname(destination_root).join("config/environments/production.rb")).exist?
10-
gsub_file env_config, /(# )?config\.active_job\.queue_adapter\s+=.*/, "config.active_job.queue_adapter = :solid_queue"
10+
unless options[:skip_adapter]
11+
if (env_config = Pathname(destination_root).join("config/environments/production.rb")).exist?
12+
say "Setting solid_queue as Active Job's queue adapter"
13+
gsub_file env_config, /(# )?config\.active_job\.queue_adapter\s+=.*/, "config.active_job.queue_adapter = :solid_queue"
14+
end
1115
end
1216

17+
say "Copying sample configuration"
1318
copy_file "config.yml", "config/solid_queue.yml"
1419
end
1520

1621
def create_migrations
17-
unless options[:skip_migrations]
18-
rails_command "railties:install:migrations FROM=solid_queue", inline: true
19-
end
22+
say "Installing database migrations"
23+
arguments = [ "FROM=solid_queue" ]
24+
arguments << "DATABASE=#{options[:database]}" if options[:database].present?
25+
rails_command "railties:install:migrations #{arguments.join(" ")}", inline: true
2026
end
2127
end

solid_queue.gemspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ Gem::Specification.new do |spec|
1111
spec.license = "MIT"
1212

1313
spec.post_install_message = <<~MESSAGE
14-
Upgrading to Solid Queue 0.4.x? There are some breaking changes about how Solid Queue is started. Check
15-
https://github.com/rails/solid_queue/blob/main/UPGRADING.md for upgrade instructions.
14+
Upgrading to Solid Queue 0.4.x? There are some breaking changes about how Solid Queue is started,
15+
configuration and new migrations. Check https://github.com/rails/solid_queue/blob/main/UPGRADING.md
16+
for upgrade instructions.
1617
MESSAGE
1718

1819
spec.metadata["homepage_uri"] = spec.homepage
1920
spec.metadata["source_code_uri"] = "https://github.com/rails/solid_queue"
2021

2122
spec.files = Dir.chdir(File.expand_path(__dir__)) do
22-
Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
23+
Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md", "UPGRADING.md"]
2324
end
2425

2526
rails_version = ">= 7.1"

0 commit comments

Comments
 (0)