38 lines
1.0 KiB
Ruby
38 lines
1.0 KiB
Ruby
require "db/mongo/mongo_connector"
|
|
|
|
module Devops
|
|
class Db
|
|
|
|
@@db = nil
|
|
|
|
class << self
|
|
def init
|
|
config = DevopsConfig.config
|
|
mongo_db = config[:mongo_db] || "devops"
|
|
mongo_host = config[:mongo_host] || "localhost"
|
|
mongo_port = config[:mongo_port] || 27017
|
|
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
|
|
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
|