From 07500c8bb91cad480c49d4afe963bb0a12a481ee Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Wed, 2 Oct 2024 15:32:29 -0400 Subject: [PATCH 1/8] Support using rails 7.1 and 7.2 versioned gems Add them to the matrix. --- .github/workflows/ci.yaml | 5 +++++ Gemfile | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4ac65dfa..4e916c62 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,6 +18,11 @@ jobs: - '3.3' rails-version: - '7.0' + - '7.1' + - '7.2' + exclude: + - ruby-version: '3.0' + rails-version: '7.2' services: postgres: image: manageiq/postgresql:13 diff --git a/Gemfile b/Gemfile index 3102353b..876a14d4 100644 --- a/Gemfile +++ b/Gemfile @@ -14,8 +14,12 @@ require File.join(Bundler::Plugin.index.load_paths("bundler-inject")[0], "bundle # your gem to rubygems.org. minimum_version = - case ENV.fetch('TEST_RAILS_VERSION', nil) - when "7.0" + case ENV['TEST_RAILS_VERSION'] + when "7.2" + "~>7.2.1" + when "7.1" + "~>7.1.4" + else # Default local bundling to use this version for generating migrations "~>7.0.8" end From 9ad9001485588cdd8742e4f54cb95c42c0499e34 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Wed, 2 Oct 2024 15:34:15 -0400 Subject: [PATCH 2/8] Set default_column_serializer to YAML for now for backward compatibility --- spec/dummy/config/application.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index a26290e4..c81ea41b 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -23,6 +23,11 @@ class Application < Rails::Application # migration specs to honor it. config.active_record.belongs_to_required_by_default = false + # Note, you can't pass kwargs :coder => YAML to serialize until rails 7.1 as it was a positional + # argument previously. To avoid a case statement in all usages of serialize, we're defaulting + # all serialized columns to YAML for rails 7.1+ here. Ideally, we would use JSON if we find we can + # use a simpler datatype. See: https://github.com/rails/rails/pull/47463 + config.active_record.default_column_serializer = YAML if Rails.version >= "7.1" config.active_record.use_yaml_unsafe_load = true end end From 3eab6b5db412f428770976f4571bf6a1083c107a Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Wed, 2 Oct 2024 15:35:06 -0400 Subject: [PATCH 3/8] Prepend serialize in 7.1+ to convert positional arguments to kwargs See https://www.github.com/rails/rails/pull/47463 --- .../serialize_positional_to_kwargs_bridge.rb | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb diff --git a/spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb b/spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb new file mode 100644 index 00000000..bffe3b99 --- /dev/null +++ b/spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb @@ -0,0 +1,23 @@ +module Dummy + module SerializePositionalToKwargsBridge + def serialize(*args, **options) + return super if Rails.version < "7.1" || options[:coder] + + # If class_name_or_coder second argument is a class, set the type + if args[1].respond_to?(:new) + options = options.merge(coder: YAML, type: args[1]) + # If no class or coder provided, assume YAML coder and Object (legacy defaults / no validation) + elsif args[1].blank? + options = options.merge(coder: YAML, type: Object) + else + # otherwise, it's a coder which should only define dump/load, so set coder + options = options.merge(coder: args[1], type: Object) + end + + # pass the first argument (drop the second) and forward the updated kwargs + super(args[0], **options) + end + end +end + +ActiveRecord::AttributeMethods::Serialization::ClassMethods.send(:prepend, Dummy::SerializePositionalToKwargsBridge) From 320a780834f7696c8ff2fd967c9edf7bd33773a2 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Fri, 4 Oct 2024 16:11:59 -0400 Subject: [PATCH 4/8] Use the rails 7.1+ serialize interface even for 7.0 We can intercept serialize for 7.0 and convert kwargs back to the positional class_name_or_coder. Update existing migrations to use rails 7.1 interface. --- ...2526_move_zone_ntp_settings_to_settings.rb | 2 +- ...06083431_convert_quadicon_settings_keys.rb | 2 +- ...conversion_host_id_to_miq_request_tasks.rb | 2 +- ...20191002103406_remove_quadicon_settings.rb | 2 +- .../20200331150436_rename_foreman_features.rb | 2 +- ...00512201614_update_chargeback_startpage.rb | 2 +- ...update_chargeback_assignments_startpage.rb | 2 +- ...200_update_chargeback_reports_startpage.rb | 2 +- ...just_control_explorer_startpage_entries.rb | 2 +- ...ut_after_policy_profile_deexplorization.rb | 2 +- ...shortcut_after_actions_de_explorization.rb | 2 +- ...cy_startpage_url_after_de_explorization.rb | 2 +- ...180202_update_policy_rsop_startpage_url.rb | 2 +- ...0226_update_policy_export_startpage_url.rb | 2 +- ...6201124_update_policy_log_startpage_url.rb | 2 +- ...ts_startpage_url_after_de_explorization.rb | 2 +- ...es_startpage_url_after_de_explorization.rb | 2 +- ...ts_startpage_url_after_de_explorization.rb | 2 +- ...ns_startpage_url_after_de_explorization.rb | 2 +- ...30_update_automation_provider_startpage.rb | 2 +- ...hortcut_after_services_de_explorization.rb | 2 +- ...5200407_fix_vpc_provision_instance_type.rb | 2 +- .../serialize_positional_to_kwargs_bridge.rb | 20 ++++++++----------- 23 files changed, 30 insertions(+), 34 deletions(-) diff --git a/db/migrate/20171103212526_move_zone_ntp_settings_to_settings.rb b/db/migrate/20171103212526_move_zone_ntp_settings_to_settings.rb index 018a6c99..5adc5c3a 100644 --- a/db/migrate/20171103212526_move_zone_ntp_settings_to_settings.rb +++ b/db/migrate/20171103212526_move_zone_ntp_settings_to_settings.rb @@ -3,7 +3,7 @@ class SettingsChange < ActiveRecord::Base serialize :value end class Zone < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20180606083431_convert_quadicon_settings_keys.rb b/db/migrate/20180606083431_convert_quadicon_settings_keys.rb index e7f15248..ddec2b8b 100644 --- a/db/migrate/20180606083431_convert_quadicon_settings_keys.rb +++ b/db/migrate/20180606083431_convert_quadicon_settings_keys.rb @@ -1,6 +1,6 @@ class ConvertQuadiconSettingsKeys < ActiveRecord::Migration[5.0] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20181001131632_add_conversion_host_id_to_miq_request_tasks.rb b/db/migrate/20181001131632_add_conversion_host_id_to_miq_request_tasks.rb index d33a66f2..641500d1 100644 --- a/db/migrate/20181001131632_add_conversion_host_id_to_miq_request_tasks.rb +++ b/db/migrate/20181001131632_add_conversion_host_id_to_miq_request_tasks.rb @@ -3,7 +3,7 @@ class MiqRequestTask < ActiveRecord::Base self.inheritance_column = :_type_disabled include ActiveRecord::IdRegions - serialize :options, Hash + serialize :options, :type => Hash belongs_to :conversion_host, :class_name => "AddConversionHostIdToMiqRequestTasks::ConversionHost" end diff --git a/db/migrate/20191002103406_remove_quadicon_settings.rb b/db/migrate/20191002103406_remove_quadicon_settings.rb index 0d98f62e..29cb2046 100644 --- a/db/migrate/20191002103406_remove_quadicon_settings.rb +++ b/db/migrate/20191002103406_remove_quadicon_settings.rb @@ -1,6 +1,6 @@ class RemoveQuadiconSettings < ActiveRecord::Migration[5.0] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20200331150436_rename_foreman_features.rb b/db/migrate/20200331150436_rename_foreman_features.rb index 86dfa7b8..36052a34 100644 --- a/db/migrate/20200331150436_rename_foreman_features.rb +++ b/db/migrate/20200331150436_rename_foreman_features.rb @@ -2,7 +2,7 @@ class RenameForemanFeatures < ActiveRecord::Migration[5.1] class MiqProductFeature < ActiveRecord::Base; end class MiqRolesFeature < ActiveRecord::Base; end class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end FEATURE_MAPPING = { diff --git a/db/migrate/20200512201614_update_chargeback_startpage.rb b/db/migrate/20200512201614_update_chargeback_startpage.rb index 2775ea38..2bbd946a 100644 --- a/db/migrate/20200512201614_update_chargeback_startpage.rb +++ b/db/migrate/20200512201614_update_chargeback_startpage.rb @@ -1,6 +1,6 @@ class UpdateChargebackStartpage < ActiveRecord::Migration[5.2] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20200520182548_update_chargeback_assignments_startpage.rb b/db/migrate/20200520182548_update_chargeback_assignments_startpage.rb index c521c5c4..7dcca221 100644 --- a/db/migrate/20200520182548_update_chargeback_assignments_startpage.rb +++ b/db/migrate/20200520182548_update_chargeback_assignments_startpage.rb @@ -1,6 +1,6 @@ class UpdateChargebackAssignmentsStartpage < ActiveRecord::Migration[5.2] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash include ActiveRecord::IdRegions end diff --git a/db/migrate/20200520210200_update_chargeback_reports_startpage.rb b/db/migrate/20200520210200_update_chargeback_reports_startpage.rb index 03eaa355..d046e8fd 100644 --- a/db/migrate/20200520210200_update_chargeback_reports_startpage.rb +++ b/db/migrate/20200520210200_update_chargeback_reports_startpage.rb @@ -1,6 +1,6 @@ class UpdateChargebackReportsStartpage < ActiveRecord::Migration[5.2] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash include ActiveRecord::IdRegions end diff --git a/db/migrate/20200910163718_adjust_control_explorer_startpage_entries.rb b/db/migrate/20200910163718_adjust_control_explorer_startpage_entries.rb index 4886f8cd..5e0f6593 100644 --- a/db/migrate/20200910163718_adjust_control_explorer_startpage_entries.rb +++ b/db/migrate/20200910163718_adjust_control_explorer_startpage_entries.rb @@ -1,6 +1,6 @@ class AdjustControlExplorerStartpageEntries < ActiveRecord::Migration[5.2] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20201227173629_update_startup_shortcut_after_policy_profile_deexplorization.rb b/db/migrate/20201227173629_update_startup_shortcut_after_policy_profile_deexplorization.rb index 7711ad1e..73c1dc2e 100644 --- a/db/migrate/20201227173629_update_startup_shortcut_after_policy_profile_deexplorization.rb +++ b/db/migrate/20201227173629_update_startup_shortcut_after_policy_profile_deexplorization.rb @@ -1,6 +1,6 @@ class UpdateStartupShortcutAfterPolicyProfileDeexplorization < ActiveRecord::Migration[5.2] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20201230005555_update_startpage_shortcut_after_actions_de_explorization.rb b/db/migrate/20201230005555_update_startpage_shortcut_after_actions_de_explorization.rb index eb8082f8..08628a61 100644 --- a/db/migrate/20201230005555_update_startpage_shortcut_after_actions_de_explorization.rb +++ b/db/migrate/20201230005555_update_startpage_shortcut_after_actions_de_explorization.rb @@ -1,6 +1,6 @@ class UpdateStartpageShortcutAfterActionsDeExplorization < ActiveRecord::Migration[5.2] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20210105011714_update_policy_startpage_url_after_de_explorization.rb b/db/migrate/20210105011714_update_policy_startpage_url_after_de_explorization.rb index ef47b401..bf8403d7 100644 --- a/db/migrate/20210105011714_update_policy_startpage_url_after_de_explorization.rb +++ b/db/migrate/20210105011714_update_policy_startpage_url_after_de_explorization.rb @@ -1,6 +1,6 @@ class UpdatePolicyStartpageUrlAfterDeExplorization < ActiveRecord::Migration[5.2] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20210106180202_update_policy_rsop_startpage_url.rb b/db/migrate/20210106180202_update_policy_rsop_startpage_url.rb index e69d93a6..880d0304 100644 --- a/db/migrate/20210106180202_update_policy_rsop_startpage_url.rb +++ b/db/migrate/20210106180202_update_policy_rsop_startpage_url.rb @@ -1,6 +1,6 @@ class UpdatePolicyRsopStartpageUrl < ActiveRecord::Migration[5.2] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20210106200226_update_policy_export_startpage_url.rb b/db/migrate/20210106200226_update_policy_export_startpage_url.rb index c0efb904..febb2d1e 100644 --- a/db/migrate/20210106200226_update_policy_export_startpage_url.rb +++ b/db/migrate/20210106200226_update_policy_export_startpage_url.rb @@ -1,6 +1,6 @@ class UpdatePolicyExportStartpageUrl < ActiveRecord::Migration[5.2] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20210106201124_update_policy_log_startpage_url.rb b/db/migrate/20210106201124_update_policy_log_startpage_url.rb index 106d93f8..7b03d44a 100644 --- a/db/migrate/20210106201124_update_policy_log_startpage_url.rb +++ b/db/migrate/20210106201124_update_policy_log_startpage_url.rb @@ -1,6 +1,6 @@ class UpdatePolicyLogStartpageUrl < ActiveRecord::Migration[5.2] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20210112000610_update_alerts_startpage_url_after_de_explorization.rb b/db/migrate/20210112000610_update_alerts_startpage_url_after_de_explorization.rb index 99d08851..5071c661 100644 --- a/db/migrate/20210112000610_update_alerts_startpage_url_after_de_explorization.rb +++ b/db/migrate/20210112000610_update_alerts_startpage_url_after_de_explorization.rb @@ -1,6 +1,6 @@ class UpdateAlertsStartpageUrlAfterDeExplorization < ActiveRecord::Migration[6.0] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20210112001749_update_alert_profiles_startpage_url_after_de_explorization.rb b/db/migrate/20210112001749_update_alert_profiles_startpage_url_after_de_explorization.rb index dcee24f7..826a2074 100644 --- a/db/migrate/20210112001749_update_alert_profiles_startpage_url_after_de_explorization.rb +++ b/db/migrate/20210112001749_update_alert_profiles_startpage_url_after_de_explorization.rb @@ -1,6 +1,6 @@ class UpdateAlertProfilesStartpageUrlAfterDeExplorization < ActiveRecord::Migration[6.0] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20210112003720_update_events_startpage_url_after_de_explorization.rb b/db/migrate/20210112003720_update_events_startpage_url_after_de_explorization.rb index 69aea8ae..3c45f6f1 100644 --- a/db/migrate/20210112003720_update_events_startpage_url_after_de_explorization.rb +++ b/db/migrate/20210112003720_update_events_startpage_url_after_de_explorization.rb @@ -1,6 +1,6 @@ class UpdateEventsStartpageUrlAfterDeExplorization < ActiveRecord::Migration[6.0] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20210112004301_update_conditions_startpage_url_after_de_explorization.rb b/db/migrate/20210112004301_update_conditions_startpage_url_after_de_explorization.rb index 06cef353..ae9a2757 100644 --- a/db/migrate/20210112004301_update_conditions_startpage_url_after_de_explorization.rb +++ b/db/migrate/20210112004301_update_conditions_startpage_url_after_de_explorization.rb @@ -1,6 +1,6 @@ class UpdateConditionsStartpageUrlAfterDeExplorization < ActiveRecord::Migration[6.0] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20210315161230_update_automation_provider_startpage.rb b/db/migrate/20210315161230_update_automation_provider_startpage.rb index 03ef60d3..98f0b837 100644 --- a/db/migrate/20210315161230_update_automation_provider_startpage.rb +++ b/db/migrate/20210315161230_update_automation_provider_startpage.rb @@ -1,6 +1,6 @@ class UpdateAutomationProviderStartpage < ActiveRecord::Migration[6.0] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20220629110748_update_startpage_shortcut_after_services_de_explorization.rb b/db/migrate/20220629110748_update_startpage_shortcut_after_services_de_explorization.rb index f0a56061..e2f06601 100644 --- a/db/migrate/20220629110748_update_startpage_shortcut_after_services_de_explorization.rb +++ b/db/migrate/20220629110748_update_startpage_shortcut_after_services_de_explorization.rb @@ -1,6 +1,6 @@ class UpdateStartpageShortcutAfterServicesDeExplorization < ActiveRecord::Migration[6.0] class User < ActiveRecord::Base - serialize :settings, Hash + serialize :settings, :type => Hash end def up diff --git a/db/migrate/20230525200407_fix_vpc_provision_instance_type.rb b/db/migrate/20230525200407_fix_vpc_provision_instance_type.rb index f6fa6e1b..a067da69 100644 --- a/db/migrate/20230525200407_fix_vpc_provision_instance_type.rb +++ b/db/migrate/20230525200407_fix_vpc_provision_instance_type.rb @@ -11,7 +11,7 @@ class MiqRequest < ActiveRecord::Base self.inheritance_column = :_type_disabled - serialize :options, Hash + serialize :options, :type => Hash end def up diff --git a/spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb b/spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb index bffe3b99..b662c2fa 100644 --- a/spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb +++ b/spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb @@ -1,21 +1,17 @@ module Dummy module SerializePositionalToKwargsBridge def serialize(*args, **options) - return super if Rails.version < "7.1" || options[:coder] + return super if Rails.version >= "7.1" - # If class_name_or_coder second argument is a class, set the type - if args[1].respond_to?(:new) - options = options.merge(coder: YAML, type: args[1]) - # If no class or coder provided, assume YAML coder and Object (legacy defaults / no validation) - elsif args[1].blank? - options = options.merge(coder: YAML, type: Object) - else - # otherwise, it's a coder which should only define dump/load, so set coder - options = options.merge(coder: args[1], type: Object) + # For rails 7.0.x, convert 7.1+ kwargs for coder/type into the positional argument + # class_name_or_coder + if options[:coder] + args << options.delete(:coder) + elsif options[:type] + args << options.delete(:type) end - # pass the first argument (drop the second) and forward the updated kwargs - super(args[0], **options) + super(*args, **options) end end end From f3d700260ee3e227b50a91fd9a29b7029b1f3697 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Fri, 4 Oct 2024 14:40:33 -0400 Subject: [PATCH 5/8] Behaviour is deprecated/removed in 7.1/7.2, use Behavior See https://www.github.com/rails/rails/pull/45180 --- spec/lib/generators/migration_generator_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/lib/generators/migration_generator_spec.rb b/spec/lib/generators/migration_generator_spec.rb index 45a589cb..8d5c07bc 100644 --- a/spec/lib/generators/migration_generator_spec.rb +++ b/spec/lib/generators/migration_generator_spec.rb @@ -3,7 +3,12 @@ require 'generators/migration/migration_generator' describe ManageIQ::Schema::MigrationGenerator do - include Rails::Generators::Testing::Behaviour + if Rails.version >= "7.1" + include Rails::Generators::Testing::Behavior + else + include Rails::Generators::Testing::Behaviour + end + include Rails::Generators::Testing::SetupAndTeardown include Rails::Generators::Testing::Assertions include FileUtils From 16b6d7e729e4456013bdc5d151ea84bf99bb375c Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Fri, 4 Oct 2024 15:58:19 -0400 Subject: [PATCH 6/8] Rails 7.2 refactored schema_migration metadata/context to the pool See: https://www.github.com/rails/rails/pull/51162 --- spec/support/migration_helper.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/spec/support/migration_helper.rb b/spec/support/migration_helper.rb index 90660b20..03c443cf 100644 --- a/spec/support/migration_helper.rb +++ b/spec/support/migration_helper.rb @@ -108,8 +108,7 @@ def suppress_migration_messages def migrate_to(version) suppress_migration_messages do migration_dir = Rails.application.config.paths["db/migrate"] - migration_conn = ::ActiveRecord::Base.connection.schema_migration - ActiveRecord::MigrationContext.new(migration_dir, migration_conn).migrate(version) + ActiveRecord::MigrationContext.new(migration_dir, schema_migration).migrate(version) end end @@ -126,16 +125,24 @@ def previous_migration_version def run_migrate migration_dir = Rails.application.config.paths["db/migrate"] - migration_conn = ::ActiveRecord::Base.connection.schema_migration - context = ActiveRecord::MigrationContext.new(migration_dir, migration_conn) + context = ActiveRecord::MigrationContext.new(migration_dir, schema_migration) context.run(migration_direction, this_migration_version) end + def schema_migration + # Rails 7.2 refactored the schema_migration metadata and context to the pool + # https://www.github.com/rails/rails/pull/51162 + if Rails.version >= "7.2" + ::ActiveRecord::Base.connection.pool.schema_migration + else + ::ActiveRecord::Base.connection.schema_migration + end + end + def schema_migrations migration_dir = Rails.application.config.paths["db/migrate"] - migration_conn = ::ActiveRecord::Base.connection.schema_migration - ActiveRecord::MigrationContext.new(migration_dir, migration_conn).migrations + ActiveRecord::MigrationContext.new(migration_dir, schema_migration).migrations end def migrations_and_index From 157860a0f3c71b9e439286daade101c4a5e9dea2 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Thu, 10 Oct 2024 12:34:38 -0400 Subject: [PATCH 7/8] Bump id_regions to support rails 7.1+ --- manageiq-schema.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manageiq-schema.gemspec b/manageiq-schema.gemspec index ceaecc22..9c888e40 100644 --- a/manageiq-schema.gemspec +++ b/manageiq-schema.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_dependency "ancestry" - spec.add_dependency "activerecord-id_regions", "~> 0.4.0" + spec.add_dependency "activerecord-id_regions", "~> 0.5.0" spec.add_dependency "manageiq-password", ">= 1.2.0", "< 2" spec.add_dependency "more_core_extensions", ">= 3.5", "< 5" spec.add_dependency "pg" From a3eb361d4f3d2fea7a39a97fcc798f8dd2190029 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Thu, 10 Oct 2024 16:23:22 -0400 Subject: [PATCH 8/8] Move SerializePositionalToKwargsBridge to the plugin itself --- lib/manageiq/schema/engine.rb | 3 ++- .../serialize_positional_to_kwargs_bridge.rb | 19 +++++++++++++++++++ .../serialize_positional_to_kwargs_bridge.rb | 19 ------------------- 3 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 lib/manageiq/schema/serialize_positional_to_kwargs_bridge.rb delete mode 100644 spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb diff --git a/lib/manageiq/schema/engine.rb b/lib/manageiq/schema/engine.rb index 6d214276..fa34dd22 100644 --- a/lib/manageiq/schema/engine.rb +++ b/lib/manageiq/schema/engine.rb @@ -9,12 +9,13 @@ class Engine < ::Rails::Engine ActiveSupport.on_load(:active_record) do require_relative 'migrate_with_cleared_schema_cache' + require_relative 'serialize_positional_to_kwargs_bridge' require_relative 'schema_statements' require_relative 'command_recorder' require_relative 'schema_dumper' ActiveRecord::Migration.prepend(MigrateWithClearedSchemaCache) - + ActiveRecord::AttributeMethods::Serialization::ClassMethods.send(:prepend, ManageIQ::Schema::SerializePositionalToKwargsBridge) ActiveRecord::ConnectionAdapters::AbstractAdapter.include(SchemaStatements) ActiveRecord::Migration::CommandRecorder.include(CommandRecorder) ActiveRecord::ConnectionAdapters::SchemaDumper.prepend(SchemaDumper) diff --git a/lib/manageiq/schema/serialize_positional_to_kwargs_bridge.rb b/lib/manageiq/schema/serialize_positional_to_kwargs_bridge.rb new file mode 100644 index 00000000..3af48bc8 --- /dev/null +++ b/lib/manageiq/schema/serialize_positional_to_kwargs_bridge.rb @@ -0,0 +1,19 @@ +module ManageIQ + module Schema + module SerializePositionalToKwargsBridge + def serialize(*args, **options) + return super if Rails.version >= "7.1" + + # For rails 7.0.x, convert 7.1+ kwargs for coder/type into the positional argument + # class_name_or_coder + if options[:coder] + args << options.delete(:coder) + elsif options[:type] + args << options.delete(:type) + end + + super(*args, **options) + end + end + end +end diff --git a/spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb b/spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb deleted file mode 100644 index b662c2fa..00000000 --- a/spec/dummy/config/initializers/serialize_positional_to_kwargs_bridge.rb +++ /dev/null @@ -1,19 +0,0 @@ -module Dummy - module SerializePositionalToKwargsBridge - def serialize(*args, **options) - return super if Rails.version >= "7.1" - - # For rails 7.0.x, convert 7.1+ kwargs for coder/type into the positional argument - # class_name_or_coder - if options[:coder] - args << options.delete(:coder) - elsif options[:type] - args << options.delete(:type) - end - - super(*args, **options) - end - end -end - -ActiveRecord::AttributeMethods::Serialization::ClassMethods.send(:prepend, Dummy::SerializePositionalToKwargsBridge)