summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/parser/interpreter.rb2
-rw-r--r--lib/puppet/rails.rb2
-rw-r--r--lib/puppet/rails/database/001_add_indexes.rb38
3 files changed, 41 insertions, 1 deletions
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index 936bc31eb..59ee43491 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -863,7 +863,7 @@ class Puppet::Parser::Interpreter
end
unless ActiveRecord::Base.connected?
- Puppet::Rails.init
+ Puppet::Rails.connect
end
# Fork the storage, since we don't need the client waiting
diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb
index 274861b8b..7f73fcf55 100644
--- a/lib/puppet/rails.rb
+++ b/lib/puppet/rails.rb
@@ -109,6 +109,8 @@ module Puppet::Rails
raise Puppet::Error, "Could not find Puppet::Rails database dir"
end
+ Puppet.notice "Migrating"
+
begin
ActiveRecord::Migrator.migrate(dbdir)
rescue => detail
diff --git a/lib/puppet/rails/database/001_add_indexes.rb b/lib/puppet/rails/database/001_add_indexes.rb
new file mode 100644
index 000000000..456501e52
--- /dev/null
+++ b/lib/puppet/rails/database/001_add_indexes.rb
@@ -0,0 +1,38 @@
+class AddIndexes < ActiveRecord::Migration
+ INDEXES = {
+ :resources => [[:title, :restype], :host_id, :exported],
+ :source_files => [:filename, :path],
+ :puppet_classes => [:name, :host_id],
+ :hosts => [:name, :ip, :updated_at],
+ :fact_names => [:name, :host_id],
+ #:fact_values => [:value, :fact_name_id],
+ #:param_values => [:value, :param_name_id],
+ :param_names => [:name, :resource_id],
+ :tags => [:name, :updated_at],
+ :taggings => [:tag_id, :taggable_id, :taggable_type]
+ }
+
+ def self.up
+ puts "trying"
+ # Add all of our initial indexes
+ INDEXES.each do |table, indexes|
+ indexes.each do |index|
+ if index.to_s =~ /_id/
+ add_index table, index, :integer => true
+ else
+ add_index table, index
+ end
+ end
+ end
+ end
+
+ def self.down
+ INDEXES.each do |table, indexes|
+ indexes.each do |index|
+ remove_index table, index
+ end
+ end
+ end
+end
+
+# $Id$