From 734743544445cf68801dea7b7abd17b12bd04146 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Mon, 14 Oct 2024 11:18:00 -0300 Subject: [PATCH] Load entire SolidQueue schema file manually into our test DB SolidQueue v0.8+ merged all the migrations into a single schema file that is automatically loaded onto the DB on a Rails app. They suggest a separate DB, which AR will handle automatically by copying over this single file schema to the app, and to use on the same DB one would have to manually move the schema to a migration and execute it. For our case, all we care about is to have SolidQueue schema / tables loaded onto our test DB. We do that by manually loading the lib's schema file via Active Record. We still execute migrations afterwards, even though it's a no-op for current SolidQueue, if they need to make new schema changes in the future, they'll come in the form of migrations. --- judoscale-solid_queue/test/test_helper.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/judoscale-solid_queue/test/test_helper.rb b/judoscale-solid_queue/test/test_helper.rb index 06e4440e..70e07b02 100644 --- a/judoscale-solid_queue/test/test_helper.rb +++ b/judoscale-solid_queue/test/test_helper.rb @@ -41,10 +41,15 @@ class TestRailsApp < Rails::Application Minitest.after_run { ActiveRecord::Tasks::DatabaseTasks.drop(DATABASE_URL) } -ActiveRecord::Base.establish_connection(DATABASE_URL) +ActiveRecord::Base.configurations = {test: {url: DATABASE_URL}} +ActiveRecord::Base.establish_connection(:test) # Suppress migration noise. ENV["VERBOSE"] ||= "false" +# SolidQueue v0.8+ merged migrations into a single schema file, which we load directly into our test DB. +# Migrations are still executed afterwards, as they may add them in the future if schema changes are needed. +SCHEMA_FILE = SolidQueue::Engine.config.paths["lib"].paths.first.join("generators", "solid_queue", "install", "templates", "db", "queue_schema.rb") +ActiveRecord::Tasks::DatabaseTasks.load_schema_current(ActiveRecord.schema_format, SCHEMA_FILE) if SCHEMA_FILE.exist? # Add SolidQueue migration path to Active Record to migrate to the latest automatically. # It seems we can't only set it on `DatabaseTasks` as expected, need to set on the `Migrator` directly instead. ActiveRecord::Migrator.migrations_paths += SolidQueue::Engine.config.paths["db/migrate"].existent