DEV: Check for pending migrations before starting the turbo tests

DEV: Check for pending migrations before starting the turbo tests

diff --git a/lib/turbo_tests.rb b/lib/turbo_tests.rb
index 337e265..acb01a9 100644
--- a/lib/turbo_tests.rb
+++ b/lib/turbo_tests.rb
@@ -1,10 +1,13 @@
 # frozen_string_literal: true
 
+require 'bundler/setup'
+
 require 'open3'
 require 'fileutils'
 require 'json'
 require 'rspec'
 require 'rails'
+require File.expand_path('../../config/environment', __FILE__)
 
 require 'parallel_tests'
 require 'parallel_tests/rspec/runner'
diff --git a/lib/turbo_tests/runner.rb b/lib/turbo_tests/runner.rb
index 650e5fe..ad9ca2b 100644
--- a/lib/turbo_tests/runner.rb
+++ b/lib/turbo_tests/runner.rb
@@ -31,6 +31,8 @@ module TurboTests
     end
 
     def run
+      check_for_migrations
+
       @num_processes = ParallelTests.determine_number_of_processes(nil)
 
       tests_in_groups =
@@ -55,6 +57,21 @@ module TurboTests
 
     protected
 
+    def check_for_migrations
+      config =
+        ActiveRecord::Base
+          .configurations["test"]
+          .merge("database" => "discourse_test_1")
+
+      conn = ActiveRecord::Base.establish_connection(config).connection
+      begin
+        ActiveRecord::Migration.check_pending!(conn)
+      rescue ActiveRecord::PendingMigrationError
+        puts "There are pending migrations, run rake parallel:migrate"
+        exit 1
+      end
+    end
+
     def setup_tmp_dir
       begin
         FileUtils.rm_r('tmp/test-pipes')

GitHub sha: 23c5da46

1 Like