This commit is contained in:
amartynov 2015-09-15 14:27:06 +03:00
parent e1d1b99ae9
commit b09968684f
4 changed files with 20 additions and 12 deletions

View File

@ -14,24 +14,13 @@ module Devops
mongo_user = config[:mongo_user]
mongo_password = config[:mongo_password]
@@db = MongoConnector.new(mongo_db, mongo_host, mongo_port, mongo_user, mongo_password)
create_indexes
@@db.create_indexes
end
def connector
@@db
end
def create_indexes
reports_coll = @@db.reports_connector
info = reports_coll.index_information
unless info["created_at_1"]
reports_coll.create_index({created_at: Mongo::ASCENDING})
end
unless info["project_1_deploy_env_1_created_at_1"]
reports_coll.create_index({project: Mongo::ASCENDING, deploy_env: Mongo::ASCENDING, created_at: Mongo::ASCENDING})
end
end
end
end
end

View File

@ -5,6 +5,11 @@ require "exceptions/invalid_privileges"
module Connectors
class Base
def create_indexes
end
# Yes, we can implement connectors without attr_accessor, storing collection directly
# in instance variable like
# @collection = db.collection('users')

View File

@ -51,6 +51,16 @@ module Connectors
collection.update({"_id" => id}, {"$set" => {"chef_node_name" => chef_node_name, "host" => host}})
end
def create_indexes
info = self.collection.index_information
unless info["created_at_1"]
self.collection.create_index({created_at: Mongo::ASCENDING})
end
unless info["project_1_deploy_env_1_created_at_1"]
self.collection.create_index({project: Mongo::ASCENDING, deploy_env: Mongo::ASCENDING, created_at: Mongo::ASCENDING})
end
end
private
def model_from_bson(bson)

View File

@ -39,6 +39,10 @@ class MongoConnector
@db.authenticate(user, password) unless user.nil? or password.nil?
end
def create_indexes
reports_connector.create_indexes
end
private
def images_connector