diff options
Diffstat (limited to 'lib/puppet/rails')
-rw-r--r-- | lib/puppet/rails/database/004_add_inventory_service_tables.rb | 6 | ||||
-rw-r--r-- | lib/puppet/rails/database/schema.rb | 4 | ||||
-rw-r--r-- | lib/puppet/rails/inventory_node.rb | 14 |
3 files changed, 6 insertions, 18 deletions
diff --git a/lib/puppet/rails/database/004_add_inventory_service_tables.rb b/lib/puppet/rails/database/004_add_inventory_service_tables.rb index a819cac1a..6e6b28c0c 100644 --- a/lib/puppet/rails/database/004_add_inventory_service_tables.rb +++ b/lib/puppet/rails/database/004_add_inventory_service_tables.rb @@ -13,12 +13,12 @@ class AddInventoryServiceTables < ActiveRecord::Migration unless ActiveRecord::Base.connection.tables.include?("inventory_facts") create_table :inventory_facts, :id => false do |t| - t.column :inventory_node_id, :integer, :null => false + t.column :node_id, :integer, :null => false t.column :name, :string, :null => false t.column :value, :text, :null => false end - add_index :inventory_facts, [:inventory_node_id, :name], :unique => true + add_index :inventory_facts, [:node_id, :name], :unique => true end end @@ -29,7 +29,7 @@ class AddInventoryServiceTables < ActiveRecord::Migration end if ActiveRecord::Base.connection.tables.include?("inventory_facts") - remove_index :inventory_facts, [:inventory_node_id, :name] + remove_index :inventory_facts, [:node_id, :name] drop_table :inventory_facts end end diff --git a/lib/puppet/rails/database/schema.rb b/lib/puppet/rails/database/schema.rb index 9fd640fe4..7b75f4216 100644 --- a/lib/puppet/rails/database/schema.rb +++ b/lib/puppet/rails/database/schema.rb @@ -114,12 +114,12 @@ class Puppet::Rails::Schema add_index :inventory_nodes, :name, :unique => true create_table :inventory_facts, :id => false do |t| - t.column :inventory_node_id, :integer, :null => false + t.column :node_id, :integer, :null => false t.column :name, :string, :null => false t.column :value, :text, :null => false end - add_index :inventory_facts, [:inventory_node_id, :name], :unique => true + add_index :inventory_facts, [:node_id, :name], :unique => true end end ensure diff --git a/lib/puppet/rails/inventory_node.rb b/lib/puppet/rails/inventory_node.rb index b3e321f94..52f8621a4 100644 --- a/lib/puppet/rails/inventory_node.rb +++ b/lib/puppet/rails/inventory_node.rb @@ -1,7 +1,7 @@ require 'puppet/rails/inventory_fact' class Puppet::Rails::InventoryNode < ::ActiveRecord::Base - has_many :facts, :class_name => "Puppet::Rails::InventoryFact", :dependent => :delete_all + has_many :facts, :class_name => "Puppet::Rails::InventoryFact", :foreign_key => :node_id, :dependent => :delete_all named_scope :has_fact_with_value, lambda { |name,value| { @@ -17,18 +17,6 @@ class Puppet::Rails::InventoryNode < ::ActiveRecord::Base } } - named_scope :has_fact, lambda { |name| - { - :conditions => ["inventory_facts.name = ?", name], - :joins => :facts - } - } - - def value_for(fact_name) - fact = facts.find_by_name(fact_name) - fact ? fact.value : nil - end - def facts_to_hash facts.inject({}) do |fact_hash,fact| fact_hash.merge(fact.name => fact.value) |