Sha256: ec89d1d9d4cf93a31f6d0171ab8828e1dabd1c64988b9d92197102eef6013c5d

Contents?: true

Size: 774 Bytes

Versions: 5

Compression:

Stored size: 774 Bytes

Contents

class AddOwnerToHosts < ActiveRecord::Migration
  class User < ActiveRecord::Base; end
  class Host < ActiveRecord::Base; end

  def self.up
    add_column :hosts, :owner_id,   :integer
    add_column :hosts, :owner_type, :string

    Host.reset_column_information

    updated = []
    email = SETTINGS[:administrator] || "root@#{Facter.domain}"
    owner = User.find_by_mail email
    owner ||= User.find_or_create_by_login(:login => "admin", :admin => true, :firstname => "Admin", :lastname => "User", :mail => email)
    unless owner.nil? or owner.id.nil?
      say "setting default owner for all hosts"
      Host.update_all("owner_id = '#{owner.id}'")
    end

  end

  def self.down
    remove_column :hosts, :owner_type
    remove_column :hosts, :owner_id
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_discovery-1.0.0 test/foreman_app/db/migrate/20100419151910_add_owner_to_hosts.rb
foreman_discovery-1.0.0.rc4 test/foreman_app/db/migrate/20100419151910_add_owner_to_hosts.rb
foreman_discovery-1.0.0.rc3 test/foreman_app/db/migrate/20100419151910_add_owner_to_hosts.rb
foreman_discovery-1.0.0.rc2 test/foreman_app/db/migrate/20100419151910_add_owner_to_hosts.rb
foreman_discovery-1.0.0.rc1 test/foreman_app/db/migrate/20100419151910_add_owner_to_hosts.rb