Sha256: 484cd06b49e25a75c9a3e2138fbb456da7582f4955e679305debbfed753f129e

Contents?: true

Size: 840 Bytes

Versions: 6

Compression:

Stored size: 840 Bytes

Contents

class AddOrganizationIdToServiceUser < ActiveRecord::Migration[6.1]
  def up
    add_column :foreman_virt_who_configure_service_users, :organization_id, :integer

    ::ForemanVirtWhoConfigure::Config.find_each do |config|
      service_user = ::ForemanVirtWhoConfigure::ServiceUser.find_by(organization_id: config.organization_id)
      if service_user.present?
         config.update_columns(service_user_id: service_user.id)
         next
      end

      cfg_service_user = ::ForemanVirtWhoConfigure::ServiceUser.find_by(id: config.service_user_id)
      cfg_service_user.update_columns(organization_id: config.organization_id)
    end

    ::ForemanVirtWhoConfigure::ServiceUser.where(organization_id: nil).destroy_all
  end

  def down
    remove_column :foreman_virt_who_configure_service_users, :organization_id, :integer
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
foreman_virt_who_configure-0.5.25 db/migrate/20231024171433_add_organization_id_to_service_user.rb
foreman_virt_who_configure-0.5.24 db/migrate/20231024171433_add_organization_id_to_service_user.rb
foreman_virt_who_configure-0.5.23 db/migrate/20231024171433_add_organization_id_to_service_user.rb
foreman_virt_who_configure-0.5.21 db/migrate/20231024171433_add_organization_id_to_service_user.rb
foreman_virt_who_configure-0.5.20 db/migrate/20231024171433_add_organization_id_to_service_user.rb
foreman_virt_who_configure-0.5.19 db/migrate/20231024171433_add_organization_id_to_service_user.rb