diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4ac65dfa7..4e916c62f 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 3102353bd..876a14d4a 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 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 018a6c99f..5adc5c3ac 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 e7f15248f..ddec2b8b1 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 d33a66f28..641500d1e 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 0d98f62e9..29cb2046d 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 86dfa7b80..36052a34e 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 2775ea384..2bbd946a7 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 c521c5c4e..7dcca2210 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 03eaa3556..d046e8fdc 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 4886f8cd7..5e0f65938 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 7711ad1e3..73c1dc2e3 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 eb8082f8b..08628a615 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 ef47b4018..bf8403d75 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 e69d93a6e..880d03049 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 c0efb9046..febb2d1e0 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 106d93f8b..7b03d44a5 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 99d08851e..5071c661d 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 dcee24f72..826a20742 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 69aea8ae4..3c45f6f17 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 06cef353b..ae9a27579 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 03ef60d39..98f0b8374 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 f0a560613..e2f06601b 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 f6fa6e1b9..a067da692 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/lib/manageiq/schema/engine.rb b/lib/manageiq/schema/engine.rb index 6d2142760..fa34dd22e 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 000000000..3af48bc80 --- /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/manageiq-schema.gemspec b/manageiq-schema.gemspec index ceaecc226..9c888e403 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" diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index a26290e40..c81ea41bb 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 diff --git a/spec/lib/generators/migration_generator_spec.rb b/spec/lib/generators/migration_generator_spec.rb index 45a589cb2..8d5c07bcc 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 diff --git a/spec/support/migration_helper.rb b/spec/support/migration_helper.rb index 90660b201..03c443cf9 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