var mongoose = require('mongoose')
var path = require('path')
var schema = require('../server/schema')
var async = require('async')
var ProductionCompany = schema.ProductionCompany
var Account = schema.Account

mongoose.connect('mongodb://localhost/meku')

async.series([importProductionCompanies, importAccounts], function() {
  mongoose.disconnect()
})


function importProductionCompanies(callback) {
  ProductionCompany.remove({}, function(err) { })

  // update production companies
  var fs = require('fs')
  fs.readFile(path.join(__dirname, '../data/meku-production-companies-samples.txt'), {encoding: 'utf8'}, function(err, data) {
    if (err) throw (err);

    var companies = data.split('\n').filter(function (x) { return x.length > 0 })

    async.each(companies, function(name, next) {
      new ProductionCompany({name: name}).save(next)
    }, callback)
  })
}

function importAccounts(callback) {
  Account.remove({}, function(err) { })

  var fs = require('fs')
  fs.readFile(path.join(__dirname, '../data/meku-production-companies-samples.txt'), {encoding: 'utf8'}, function(err, data) {
    if (err) throw err;

    var accounts = data.split('\n').filter(function (x) { return x.length > 0 })

    async.each(accounts, function(name, next) {
      new Account({name: name}).save(next)
    }, callback)
  })
}


@@ -293,24 +293,8 @@
 nies
-, importAccounts
 %5D, f
@@ -858,456 +858,4 @@
 %0A%7D%0A%0A
-function importAccounts(callback) %7B%0A  Account.remove(%7B%7D, function(err) %7B %7D)%0A%0A  var fs = require('fs')%0A  fs.readFile(path.join(__dirname, '../data/meku-production-companies-samples.txt'), %7Bencoding: 'utf8'%7D, function(err, data) %7B%0A    if (err) throw err;%0A%0A    var accounts = data.split('%5Cn').filter(function (x) %7B return x.length %3E 0 %7D)%0A%0A    async.each(accounts, function(name, next) %7B%0A      new Account(%7Bname: name%7D).save(next)%0A    %7D, callback)%0A  %7D)%0A%7D%0A%0A

Remove account sample data import code