From 8ce30c83ddba87ba7e2622a46f27143159132789 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Mon, 7 Mar 2011 15:19:20 -0800 Subject: (#6338) Add an InventoryActiveRecord terminus for Facts So far this terminus only supports find and save. Search is forthcoming. It uses two new tables (inventory_host and inventory_facts) so that it won't interact with storedconfigs. Paired-With: Jacob Helwig --- .../database/004_add_inventory_service_tables.rb | 36 ++++++++++++++++++++++ lib/puppet/rails/database/schema.rb | 17 ++++++++++ 2 files changed, 53 insertions(+) create mode 100644 lib/puppet/rails/database/004_add_inventory_service_tables.rb (limited to 'lib/puppet/rails/database') diff --git a/lib/puppet/rails/database/004_add_inventory_service_tables.rb b/lib/puppet/rails/database/004_add_inventory_service_tables.rb new file mode 100644 index 000000000..22298437a --- /dev/null +++ b/lib/puppet/rails/database/004_add_inventory_service_tables.rb @@ -0,0 +1,36 @@ +class AddInventoryServiceTables < ActiveRecord::Migration + def self.up + unless ActiveRecord::Base.connection.tables.include?("inventory_hosts") + create_table :inventory_hosts do |t| + t.column :name, :string, :null => false + t.column :timestamp, :datetime, :null => false + t.column :updated_at, :datetime + t.column :created_at, :datetime + end + + add_index :inventory_hosts, :name, :unique => true + end + + unless ActiveRecord::Base.connection.tables.include?("inventory_facts") + create_table :inventory_facts, :id => false do |t| + t.column :inventory_host_id, :integer, :null => false + t.column :name, :string, :null => false + t.column :value, :text, :null => false + end + + add_index :inventory_facts, [:inventory_host_id, :name], :unique => true + end + end + + def self.down + unless ActiveRecord::Base.connection.tables.include?("inventory_hosts") + remove_index :inventory_hosts, :name + drop_table :inventory_hosts + end + + if ActiveRecord::Base.connection.tables.include?("inventory_facts") + remove_index :inventory_facts, [:inventory_host_id, :name] + drop_table :inventory_facts + end + end +end diff --git a/lib/puppet/rails/database/schema.rb b/lib/puppet/rails/database/schema.rb index 8b389d773..5e455d6c0 100644 --- a/lib/puppet/rails/database/schema.rb +++ b/lib/puppet/rails/database/schema.rb @@ -103,6 +103,23 @@ class Puppet::Rails::Schema t.column :created_at, :datetime end add_index :param_names, :name + + create_table :inventory_hosts do |t| + t.column :name, :string, :null => false + t.column :timestamp, :datetime, :null => false + t.column :updated_at, :datetime + t.column :created_at, :datetime + end + + add_index :inventory_hosts, :name, :unique => true + + create_table :inventory_facts, :id => false do |t| + t.column :inventory_host_id, :integer, :null => false + t.column :name, :string, :null => false + t.column :value, :text, :null => false + end + + add_index :inventory_facts, [:inventory_host_id, :name], :unique => true end end ensure -- cgit From 3489412a03fec009bc42222f449077e6f14998a4 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Wed, 9 Mar 2011 12:55:03 -0800 Subject: maint: Rename InventoryHost to InventoryNode This had been conflating hosts and nodes, when nodes is the most accurate. --- .../rails/database/004_add_inventory_service_tables.rb | 18 +++++++++--------- lib/puppet/rails/database/schema.rb | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'lib/puppet/rails/database') 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 22298437a..a819cac1a 100644 --- a/lib/puppet/rails/database/004_add_inventory_service_tables.rb +++ b/lib/puppet/rails/database/004_add_inventory_service_tables.rb @@ -1,35 +1,35 @@ class AddInventoryServiceTables < ActiveRecord::Migration def self.up - unless ActiveRecord::Base.connection.tables.include?("inventory_hosts") - create_table :inventory_hosts do |t| + unless ActiveRecord::Base.connection.tables.include?("inventory_nodes") + create_table :inventory_nodes do |t| t.column :name, :string, :null => false t.column :timestamp, :datetime, :null => false t.column :updated_at, :datetime t.column :created_at, :datetime end - add_index :inventory_hosts, :name, :unique => true + add_index :inventory_nodes, :name, :unique => true end unless ActiveRecord::Base.connection.tables.include?("inventory_facts") create_table :inventory_facts, :id => false do |t| - t.column :inventory_host_id, :integer, :null => false + t.column :inventory_node_id, :integer, :null => false t.column :name, :string, :null => false t.column :value, :text, :null => false end - add_index :inventory_facts, [:inventory_host_id, :name], :unique => true + add_index :inventory_facts, [:inventory_node_id, :name], :unique => true end end def self.down - unless ActiveRecord::Base.connection.tables.include?("inventory_hosts") - remove_index :inventory_hosts, :name - drop_table :inventory_hosts + unless ActiveRecord::Base.connection.tables.include?("inventory_nodes") + remove_index :inventory_nodes, :name + drop_table :inventory_nodes end if ActiveRecord::Base.connection.tables.include?("inventory_facts") - remove_index :inventory_facts, [:inventory_host_id, :name] + remove_index :inventory_facts, [:inventory_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 5e455d6c0..9fd640fe4 100644 --- a/lib/puppet/rails/database/schema.rb +++ b/lib/puppet/rails/database/schema.rb @@ -104,22 +104,22 @@ class Puppet::Rails::Schema end add_index :param_names, :name - create_table :inventory_hosts do |t| + create_table :inventory_nodes do |t| t.column :name, :string, :null => false t.column :timestamp, :datetime, :null => false t.column :updated_at, :datetime t.column :created_at, :datetime end - add_index :inventory_hosts, :name, :unique => true + add_index :inventory_nodes, :name, :unique => true create_table :inventory_facts, :id => false do |t| - t.column :inventory_host_id, :integer, :null => false + t.column :inventory_node_id, :integer, :null => false t.column :name, :string, :null => false t.column :value, :text, :null => false end - add_index :inventory_facts, [:inventory_host_id, :name], :unique => true + add_index :inventory_facts, [:inventory_node_id, :name], :unique => true end end ensure -- cgit From 8858e40839bd693420ddc791df6b51de79356d2a Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Fri, 11 Mar 2011 15:22:23 -0800 Subject: (#6689) Make inventory_active_record terminus search quickly This terminus behaves the same on all supported DB platforms, by performing a limited portion of its query in SQL, and the rest of the comparison in Ruby. Its results are consistent with the YAML terminus. Paired-With: Jesse Wolfe --- lib/puppet/rails/database/004_add_inventory_service_tables.rb | 6 +++--- lib/puppet/rails/database/schema.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/puppet/rails/database') 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 -- cgit