Installation: provide a production-safe, queue-only database setup command
Maintainer thường phản hồi trong vòng 4 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Start with the installation guide and the Rails 7.2 task behavior cited in the issue, especially the db:schema:load:queue prerequisite and the db:prepare implementation. Compare the existing queue-scoped setup options against the requested safety constraints; done means documenting or providing a supported path that initializes only the queue database without seeds, unrelated migrations, or test-database access.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
The installation guide currently recommends running db:prepare in production after configuring a separate Solid Queue database:
Then run
db:preparein production to ensure the database is created and the schema is loaded.
For an existing production application, this command is not scoped to Solid Queue. It can execute the application's db/seeds.rb and run pending migrations for other databases, including the primary database.
The apparent queue-specific alternative, bin/rails db:schema:load:queue, is not reliable either on Rails 7.2.3.2: it invokes db:test:purge:queue first and therefore requires a configured and accessible test database, even when RAILS_ENV=production.
Could Solid Queue provide or document a supported installation path that initializes only the queue database, without touching the test database, running application seeds, or migrating unrelated databases?
Environment
-
Solid Queue: 1.7.2
-
Rails: 7.2.3.2
-
Ruby: 3.4.10
-
Database: MySQL
-
Setup: an existing production application with a populated primary database and a new, separate queue database
Why db:prepare is risky for this installation scenario
In Rails 7.2.3.2, db:prepare calls ActiveRecord::Tasks::DatabaseTasks.prepare_all, which iterates over all database configurations for the current environment.
Its implementation sets seed = true whenever any database is considered uninitialized, and eventually calls:
load_seed if seed
Source:
Consequently, adding a new queue database is enough to trigger the application's seed loader, even if the primary database has existed for years and is already fully initialized.
This is unsafe for applications whose db/seeds.rb is not idempotent or contains administrative data changes. A command run solely to install Solid Queue should not unexpectedly execute application seed logic against an existing production system.
The same implementation also runs migrations for the current environment's database configurations, so pending primary-database migrations may be executed as part of the Solid Queue installation.
There is an additional edge case around schema loading: Rails determines whether a database is initialized by checking for schema_migrations. If an existing database does not have that table, db:prepare may load its schema; schemas containing force: :cascade can then recreate existing tables.
To be clear, I am not saying that db:prepare always reloads the primary schema or drops production tables. An initialized primary database is normally not schema-loaded. The concern is that its application-wide behavior is much broader and more state-dependent than what is needed to initialize Solid Queue.
Why db:schema:load:queue does not solve the problem
Running:
RAILS_ENV=production bin/rails db:schema:load:queue
fails with:
bin/rails aborted!
TypeError: Invalid type for configuration. Expected Symbol, String, or Hash. Got nil (TypeError)
Tasks: TOP => db:schema:load:queue => db:test:purge:queue
On Rails 7.2.3.2, the named schema-loading task has a hard-coded prerequisite:
task name => "db:test:purge:#{name}"
Source:
That prerequisite explicitly resolves the database configuration using the test environment:
ActiveRecord::Tasks::DatabaseTasks.with_temporary_pool_for_each(
env: "test",
name: name
)
Source:
If test.queue is not configured, the lookup returns nil, which eventually causes the TypeError above. If a test configuration exists but no test database is available on the production host, the task may instead fail while trying to connect to it.
Production servers commonly have no test database at all, by design. Requiring one merely to initialize a production queue database makes this an unsuitable deployment workaround.
I understand that this prerequisite comes from Active Record rather than Solid Queue. I also noticed that Rails PR https://github.com/rails/rails/pull/54853 removes this test-database purge behavior. However, affected released Rails versions are still in use, and Solid Queue supports Rails 7.1 and later, so a reliable installation path is still needed for those versions.
Other available commands do not provide a complete alternative
-
db:schema:loadis not queue-scoped and may load every configured production schema, including the primary schema. -
db:migrate:queuecannot perform the initial installation from the generateddb/queue_schema.rbwhendb/queue_migratecontains no initial migration. -
Rails 7.2 does not provide a db:prepare:queue task.
-
Manually establishing a connection and loading
db/queue_schema.rbthrough rails runner or rails console works as a workaround, but it is not a clear, supported installation procedure and is easy to execute against the wrong database.
Request
Could Solid Queue provide an official queue-scoped setup command, for example solid_queue:setup, with the following behavior?
-
Create only the configured queue database if it does not exist.
-
Load only
db/queue_schema.rbwhen the queue database needs initialization. -
Never execute the application's
db/seeds.rb. -
Never run migrations for the primary or other unrelated databases.
-
Never require or connect to a test database.
Alternatively, a documented migration-based installation path for existing production applications would also solve this problem.
At minimum, it would be helpful for the installation guide to warn that db:prepare may execute application seeds and unrelated pending migrations, and to document a safe queue-only alternative for existing production applications.
Related reports:
- Ngôn ngữ chính
- Ruby
- Star
- 2.5k
- Fork
- 271
- Merge trung bình
- 5 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 5
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rails/solid_queue
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
rails/solid_queue#838 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
rails/solid_queue#834 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
rails/solid_queue#824 · 1 reaction ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 42/100
rails/solid_queue#808 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
rails/solid_queue#806 ·
Maintainer thường phản hồi trong vòng 4 ngày
Tất cả issue của rails/solid_queue
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
jenkins-infra/jenkins.io#9615 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix(ocr): compile the Tesseract-free pipeline with Tokio runtimeCó thể đã có người làm @Goldziher đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
WhatsApp Cloud template sync saves a partial template list when one page of the Graph API response failsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Remove the tcpwrappers assertion that can no longer fail from the simp:defaults profile specĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
simp/pupmod-simp-ssh#270 ·