Method: CloudCrowd.configure_database

Defined in:
lib/cloud-crowd.rb

.configure_database(config_path, validate_schema = true) ⇒ Object

Configure the CloudCrowd central database (and connect to it), by passing in a path to database.yml. The file should use the standard ActiveRecord connection format.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/cloud-crowd.rb', line 113

def configure_database(config_path, validate_schema=true)
  configuration = YAML.load(ERB.new(File.read(config_path)).result)
  ActiveRecord::Base.establish_connection(configuration)
  if validate_schema
    begin
      version = ActiveRecord::Base.connection.select_values('select max(version) from schema_migrations').first.to_i
    rescue
      version = 0
    end
    return true if version == SCHEMA_VERSION
    puts "Your database schema is out of date. Please use `crowd load_schema` to update it. This will wipe all the tables, so make sure that your jobs have a chance to finish first.\nexiting..."
    exit
  end
end