From 013deb58f194781638fcb69706a8dcd8d313553c Mon Sep 17 00:00:00 2001
From: Hiro Asari <asari.ruby@gmail.com>
Date: Wed, 18 Jun 2014 12:56:35 -0400
Subject: [PATCH] Run core's extra migrations without JRuby

Instead of cloning travis-logs and using JRuby to run migrations
try copying core's extra migrations to db/migrate
and run migrations straight up.
---
 .travis.yml           |  6 +-----
 Rakefile              | 14 +++++++++++++-
 set_up_travis_logs.sh | 38 --------------------------------------
 3 files changed, 14 insertions(+), 44 deletions(-)
 delete mode 100755 set_up_travis_logs.sh

diff --git a/.travis.yml b/.travis.yml
index 7341d32b..231e1e66 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,11 +9,7 @@ addons:
   postgresql: 9.3
 before_script:
   # create 'logs' table matching 'travis-logs'
-  - ./set_up_travis_logs.sh
-  - 'RAILS_ENV=test bundle exec rake db:create db:structure:load --trace'
-  # replace 'logs' table in travis_test DB with that in travis_logs_test
-  - psql -c "DROP TABLE IF EXISTS logs CASCADE" -U postgres travis_test
-  - pg_dump -t logs travis_logs_test | psql -U postgres travis_test
+  - 'RAILS_ENV=test bundle exec rake db:create db:structure:load mv_migrations db:migrate --trace'
 
 notifications:
   irc: "irc.freenode.org#travis"
diff --git a/Rakefile b/Rakefile
index 3fe4f809..cc2ec531 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,5 +1,6 @@
 require 'bundler/setup'
-ENV['DB_STRUCTURE'] = "#{Gem.loaded_specs['travis-core'].full_gem_path}/db/structure.sql"
+CORE_PATH = Gem.loaded_specs['travis-core'].full_gem_path
+ENV['DB_STRUCTURE'] = "#{CORE_PATH}/db/structure.sql"
 
 begin
   require 'micro_migrations'
@@ -16,6 +17,17 @@ rescue LoadError
   warn "could not load rspec"
 end
 
+desc "move travis-core-specific migrations to db/migrate"
+task 'mv_migrations' do
+  require 'fileutils'
+  migration_files = Dir["#{CORE_PATH}/spec/migrations/**/*.rb"]
+  migration_files.each do |f|
+    dest = 'db/migrate'
+    FileUtils.mkdir_p dest
+    FileUtils.cp f, dest
+  end
+end
+
 desc "generate gemspec"
 task 'travis-api.gemspec' do
   content = File.read 'travis-api.gemspec'
diff --git a/set_up_travis_logs.sh b/set_up_travis_logs.sh
deleted file mode 100755
index 54569ecb..00000000
--- a/set_up_travis_logs.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/bin/bash
-
-travis_retry() {
-  local result=0
-  local count=1
-  while [ $count -le 3 ]; do
-    [ $result -ne 0 ] && {
-      echo -e "\n${RED}The command \"$@\" failed. Retrying, $count of 3.${RESET}\n" >&2
-    }
-    "$@"
-    result=$?
-    [ $result -eq 0 ] && break
-    count=$(($count + 1))
-    sleep 1
-  done
-
-  [ $count -eq 3 ] && {
-    echo "\n${RED}The command \"$@\" failed 3 times.${RESET}\n" >&2
-  }
-
-  return $result
-}
-
-# clone travis-logs
-pushd $HOME
-git clone --depth=1 https://github.com/travis-ci/travis-logs.git
-cd travis-logs
-
-# install ruby runtime which travis-logs wants
-RUBY_RUNTIME=$(cat .ruby-version)
-rvm install $RUBY_RUNTIME
-# using JRuby, migrate the 'logs' table in 'travis_test' database
-BUNDLE_GEMFILE=$PWD/Gemfile
-travis_retry rvm $RUBY_RUNTIME do bundle install
-psql -c "CREATE DATABASE travis_logs_test;" -U postgres
-cp $TRAVIS_BUILD_DIR/config/database.yml config/travis.yml
-rvm $RUBY_RUNTIME do bundle exec rake db:migrate
-popd