Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into radjabov
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryguy committed Nov 4, 2024
2 parents 7400a8a + fe983e4 commit 81938f5
Show file tree
Hide file tree
Showing 34 changed files with 233 additions and 35 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ jobs:
matrix:
ruby-version:
- '3.1'
- '3.2'
- '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
Expand Down Expand Up @@ -45,4 +52,4 @@ jobs:
- name: Report code coverage
if: ${{ github.ref == 'refs/heads/master' && matrix.ruby-version == '3.1' && matrix.rails-version == '7.0' }}
continue-on-error: true
uses: paambaati/codeclimate-action@v8
uses: paambaati/codeclimate-action@v9
8 changes: 6 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ConvertQuadiconSettingsKeys < ActiveRecord::Migration[5.0]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20191002103406_remove_quadicon_settings.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class RemoveQuadiconSettings < ActiveRecord::Migration[5.0]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20200331150436_rename_foreman_features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20200512201614_update_chargeback_startpage.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UpdateChargebackStartpage < ActiveRecord::Migration[5.2]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class AdjustControlExplorerStartpageEntries < ActiveRecord::Migration[5.2]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UpdateStartupShortcutAfterPolicyProfileDeexplorization < ActiveRecord::Migration[5.2]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UpdateStartpageShortcutAfterActionsDeExplorization < ActiveRecord::Migration[5.2]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UpdatePolicyStartpageUrlAfterDeExplorization < ActiveRecord::Migration[5.2]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UpdatePolicyRsopStartpageUrl < ActiveRecord::Migration[5.2]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UpdatePolicyExportStartpageUrl < ActiveRecord::Migration[5.2]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UpdatePolicyLogStartpageUrl < ActiveRecord::Migration[5.2]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UpdateAlertsStartpageUrlAfterDeExplorization < ActiveRecord::Migration[6.0]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UpdateAlertProfilesStartpageUrlAfterDeExplorization < ActiveRecord::Migration[6.0]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UpdateEventsStartpageUrlAfterDeExplorization < ActiveRecord::Migration[6.0]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UpdateConditionsStartpageUrlAfterDeExplorization < ActiveRecord::Migration[6.0]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UpdateAutomationProviderStartpage < ActiveRecord::Migration[6.0]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UpdateStartpageShortcutAfterServicesDeExplorization < ActiveRecord::Migration[6.0]
class User < ActiveRecord::Base
serialize :settings, Hash
serialize :settings, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MiqRequest < ActiveRecord::Base

self.inheritance_column = :_type_disabled

serialize :options, Hash
serialize :options, :type => Hash
end

def up
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class UpdateResourcePoolIdentifiersToMiqProductFeatures < ActiveRecord::Migration[6.1]
class MiqProductFeature < ActiveRecord::Base; end

FEATURE_MAPPING_UPDATE = {
'resource_pool' => 'resource_pool_infra',
'resource_pool_view' => 'resource_pool_infra_view',
'resource_pool_show_list' => 'resource_pool_infra_show_list',
'resource_pool_show' => 'resource_pool_infra_show',
'resource_pool_control' => 'resource_pool_infra_control',
'resource_pool_tag' => 'resource_pool_infra_tag',
'resource_pool_protect' => 'resource_pool_infra_protect',
'resource_pool_admin' => 'resource_pool_infra_admin',
'resource_pool_delete' => 'resource_pool_infra_delete'
}.freeze

def up
return if MiqProductFeature.none?

say_with_time('Updating resource_pool features to resource_pool_infra') do
FEATURE_MAPPING_UPDATE.each do |from, to|
MiqProductFeature.find_by(:identifier => from)&.update!(:identifier => to)
end
end
end

def down
return if MiqProductFeature.none?

say_with_time('Reverting resource_pool_infra features back to resource_pool') do
FEATURE_MAPPING_UPDATE.each do |to, from|
MiqProductFeature.find_by(:identifier => from)&.update!(:identifier => to)
end
end
end
end
35 changes: 35 additions & 0 deletions db/migrate/20240830172702_reset_resource_pool_identifiers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class ResetResourcePoolIdentifiers < ActiveRecord::Migration[6.1]
class MiqProductFeature < ActiveRecord::Base; end

FEATURE_MAPPING_UPDATE = {
'resource_pool_infra' => 'resource_pool',
'resource_pool_infra_view' => 'resource_pool_view',
'resource_pool_infra_show_list' => 'resource_pool_show_list',
'resource_pool_infra_show' => 'resource_pool_show',
'resource_pool_infra_control' => 'resource_pool_control',
'resource_pool_infra_tag' => 'resource_pool_tag',
'resource_pool_infra_protect' => 'resource_pool_protect',
'resource_pool_infra_admin' => 'resource_pool_admin',
'resource_pool_infra_delete' => 'resource_pool_delete'
}.freeze

def up
return if MiqProductFeature.none?

say_with_time('Resetting resource_pool_infra features back to resource_pool') do
FEATURE_MAPPING_UPDATE.each do |from, to|
MiqProductFeature.find_by(:identifier => from)&.update!(:identifier => to)
end
end
end

def down
return if MiqProductFeature.none?

say_with_time('Updating resource_pool features to resource_pool_infra') do
FEATURE_MAPPING_UPDATE.each do |to, from|
MiqProductFeature.find_by(:identifier => from)&.update!(:identifier => to)
end
end
end
end
3 changes: 2 additions & 1 deletion lib/manageiq/schema/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions lib/manageiq/schema/serialize_positional_to_kwargs_bridge.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions manageiq-schema.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ 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"
spec.add_dependency "rails", ">=6.0.4", "<7.1"
spec.add_dependency "rails", ">=7.0.8.5", "<8.0"

spec.add_development_dependency "manageiq-style", ">= 1.5.2"
spec.add_development_dependency "rspec"
Expand Down
5 changes: 5 additions & 0 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion spec/lib/generators/migration_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 81938f5

Please sign in to comment.