web/db/seeds-common.rb
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 21 Mar 2016 13:15:35 +0100
changeset 314 9ac0be200068
parent 273 b6df14688f46
permissions -rw-r--r--
CI: Added CI scripts for Pharo ...to make Jenkins setup easier. To run CalipeL/S tests on Pharo, simply execute: wget -O "ci-pharo-common.sh" https://bitbucket.org/janvrany/jv-calipel/raw/tip/s/pharo/ci/ci-pharo-tests.sh | bash -x To run standard set ob benchmarks on Pharo, run wget -O "ci-pharo-common.sh" https://bitbucket.org/janvrany/jv-calipel/raw/tip/s/pharo/ci/ci-pharo-benchmarks.sh | bash -x
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
273
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     1
# This file contains helper function to seed database from
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     2
# a set of .json reports. Used by db:seed and db:seed:production-archive
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     3
# rake tasks
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     4
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     5
def db_seed(directory, timestamp=nil)
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     6
  if not File.directory?(directory) then
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     7
    raise Exception.new("#{directory} is not a valid directory")
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     8
  end
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     9
  Dir.glob(File.join(directory, '*.json')).each do | json_file |
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    10
    json = JSON.parse( IO.read( json_file)  )
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    11
    if timestamp != nil
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    12
      json['timestamp'] = timestamp.strftime("%Y-%m-%dT%H:%M:%S.%LZ")
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    13
    end
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    14
    puts "Loading #{json_file}..."
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
    BenchmarkBatch.from_json json
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
  end
b6df14688f46 Web: added task db:seed:production-archive to seed DB from acrhived .jsons
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
end