From 1adeaf6cefcb5cac143c4e9b5a4bfeeab973f392 Mon Sep 17 00:00:00 2001 From: louispt1 Date: Mon, 17 Aug 2026 14:37:18 +0200 Subject: [PATCH] Never raise a scenario migration error on the test db and allow the 'no scenarios migrated' check to be skipped when an ENV var SKIP_SCENARIO_CHECK=1 is set --- lib/etengine/scenario_migration.rb | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/etengine/scenario_migration.rb b/lib/etengine/scenario_migration.rb index fd9eb9269..70390d1eb 100644 --- a/lib/etengine/scenario_migration.rb +++ b/lib/etengine/scenario_migration.rb @@ -5,6 +5,10 @@ module ETEngine module ScenarioMigration NoScenariosMigrated = Class.new(RuntimeError) + NO_CHANGES_MESSAGE = + 'No scenarios were changed. If this database holds no scenarios the migration ' \ + 'applies to, re-run with SKIP_SCENARIO_CHECK=1 to record it as applied.' + # Public: Yields all migrateable scenarios. If a scenario is changed while # yielded it will be saved. # @@ -18,7 +22,8 @@ module ScenarioMigration # Raises an error if no scenarios were migrated. This is useful if you are # expecting scenarios to be migrated and want to fail the migration if # none were. This is particularly valuable when deploying automatically - # where this might not be noticed. (default: true) + # where this might not be noticed. Never raises while migrating the test + # database. (default: true) # # since: - # By default, all read-only scenarios and writeable scenarios modified @@ -53,9 +58,10 @@ def migrate_scenarios(raise_if_no_changes: true, since: nil) say("#{total}/#{total} (#{changed} migrated)") # With continuous deployment, it might go unnoticed if no scenarios are - # migrated. If the developer knows that zero migrated scenarios is an - # error, they may - raise NoScenariosMigrated if changed.zero? && raise_if_no_changes + # migrated. + if raise_if_no_changes && changed.zero? && !skip_no_changes_check? + raise NoScenariosMigrated, NO_CHANGES_MESSAGE + end nil end @@ -66,6 +72,15 @@ def down private + def skip_no_changes_check? + test_database? || ENV['SKIP_SCENARIO_CHECK'].present? + end + + # True while migrating the test database. + def test_database? + ActiveRecord::Base.connection_db_config.env_name == 'test' + end + def scenarios(since) since.nil? ? Scenario.migratable : Scenario.migratable_since(since) end