80: def self.migrate
81: dbdir = nil
82: $:.each { |d|
83: tmp = File.join(d, "puppet/rails/database")
84: if FileTest.directory?(tmp)
85: dbdir = tmp
86: break
87: end
88: }
89:
90: unless dbdir
91: raise Puppet::Error, "Could not find Puppet::Rails database dir"
92: end
93:
94: unless ActiveRecord::Base.connection.tables.include?("resources")
95: raise Puppet::Error, "Database has problems, can't migrate."
96: end
97:
98: Puppet.notice "Migrating"
99:
100: begin
101: ActiveRecord::Migrator.migrate(dbdir)
102: rescue => detail
103: if Puppet[:trace]
104: puts detail.backtrace
105: end
106: raise Puppet::Error, "Could not migrate database: %s" % detail
107: end
108: end