packages/udaru-hapi-server/bench/util/loadVolumeData.js
function loadUsers (startId, orgId, teamId, callback) {
  // insert users
  console.log('inserting users ' + startId + ' to ' + (startId + NUM_USERS_PER_TEAM - 1) + ' into team: ' + teamId)

  var userSql = 'INSERT INTO users (id, name, org_id, metadata)\nVALUES\n'
  var userTeamSql = 'INSERT INTO team_members (user_id, team_id)\nVALUES\n'
  for (var id = startId; id < (startId + NUM_USERS_PER_TEAM); id++) {
    userSql += "('" + id + "', 'USER_" + id + "', '" + orgId + "'," + getMetaData(id, orgId) + ')'
    userTeamSql += "('" + id + "', '" + teamId + "')"

    if (id === startId + NUM_USERS_PER_TEAM - 1) {
      userSql += ';'
      userTeamSql += ';'
    } else {
      userSql += ',\n'
      userTeamSql += ',\n'
    }
  }

  var fixturesSQL = 'BEGIN;\n'
  fixturesSQL += userSql + '\n'
  fixturesSQL += userTeamSql + '\n'
  fixturesSQL += 'COMMIT;\n'

  client.query(fixturesSQL, function (err, result) {
    if (err) {
      callback(err)
    } else {
      console.log(chalk.green('success inserting users ' + startId +
        ' to ' + (startId + NUM_USERS_PER_TEAM - 1)))
      if (teamId < NUM_TEAMS + TEAM_START_ID - 1) {
        loadUsers(id, orgId, teamId + 1, callback)
      } else {
        loadVolumeDataEnd(callback)
      }
    }
  })
}
function loadUsers (startId, orgId, teamId, callback) {
  // insert users
  console.log('inserting users ' + startId + ' to ' + (startId + NUM_USERS_PER_TEAM - 1) + ' into team: ' + teamId)

  var userSql = 'INSERT INTO users (id, name, org_id, metadata)\nVALUES\n'
  var userTeamSql = 'INSERT INTO team_members (user_id, team_id)\nVALUES\n'
  for (var id = startId; id < (startId + NUM_USERS_PER_TEAM); id++) {
    userSql += "('" + id + "', 'USER_" + id + "', '" + orgId + "'," + getMetaData(id, orgId) + ')'
    userTeamSql += "('" + id + "', '" + teamId + "')"

    if (id === startId + NUM_USERS_PER_TEAM - 1) {
      userSql += ';'
      userTeamSql += ';'
    } else {
      userSql += ',\n'
      userTeamSql += ',\n'
    }
  }

  var fixturesSQL = 'BEGIN;\n'
  fixturesSQL += userSql + '\n'
  fixturesSQL += userTeamSql + '\n'
  fixturesSQL += 'COMMIT;\n'

  client.query(fixturesSQL, function (err, result) {
    if (err) {
      callback(err)
    } else {
      console.log(chalk.green('success inserting users ' + startId +
        ' to ' + (startId + NUM_USERS_PER_TEAM - 1)))
      if (teamId < NUM_TEAMS + TEAM_START_ID - 1) {
        loadUsers(id, orgId, teamId + 1, callback)
      } else {
        loadVolumeDataEnd(callback)
      }
    }
  })
}
function loadUsers ( startId , orgId , teamId , callback ) { // insert users console . log ( 'inserting users ' + startId + ' to ' + ( startId + NUM_USERS_PER_TEAM - 1 ) + ' into team: ' + teamId ) var userSql = 'INSERT INTO users (id, name, org_id, metadata)\nVALUES\n' var userTeamSql = 'INSERT INTO team_members (user_id, team_id)\nVALUES\n' for ( var id = startId ; id < ( startId + NUM_USERS_PER_TEAM ) ; id ++ ) { userSql += "('" + id + "', 'USER_" + id + "', '" + orgId + "'," + getMetaData ( id , orgId ) + ')' userTeamSql += "('" + id + "', '" + teamId + "')" if ( id === startId + NUM_USERS_PER_TEAM - 1 ) { userSql += ';' userTeamSql += ';' } else { userSql += ',\n' userTeamSql += ',\n' } } var fixturesSQL = 'BEGIN;\n' fixturesSQL += userSql + '\n' fixturesSQL += userTeamSql + '\n' fixturesSQL += 'COMMIT;\n' client . query ( fixturesSQL , function ( err , result ) { if ( err ) { callback ( err ) } else { console . log ( chalk . green ( 'success inserting users ' + startId + ' to ' + ( startId + NUM_USERS_PER_TEAM - 1 ) ) ) if ( teamId < NUM_TEAMS + TEAM_START_ID - 1 ) { loadUsers ( id , orgId , teamId + 1 , callback ) } else { loadVolumeDataEnd ( callback ) } } } ) }
insert users and add them to teams in batches
insert users and add them to teams in batches