deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [7/8] git commit: Pull all DB setup logic into the database initializer
Date Thu, 07 Mar 2013 11:22:16 GMT
Pull all DB setup logic into the database initializer

This ensures in particular that our tests always run under the same
environment.
TrackedAt: http://tracker.deltacloud.org/patch/5ec21300d23fc4fddfc4a75a237d417ba83d5bb6


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/332b2d38
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/332b2d38
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/332b2d38

Branch: refs/heads/master
Commit: 332b2d3831c760a8e3e425b621e529c4f41c09de
Parents: c063da8
Author: David Lutterkort <lutter@redhat.com>
Authored: Wed Mar 6 17:57:09 2013 -0800
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Thu Mar 7 12:17:18 2013 +0100

----------------------------------------------------------------------
 server/bin/deltacloud-db-upgrade               |   11 +-------
 server/lib/initializers/database_initialize.rb |   27 +++++++++++++-----
 server/tests/cimi/db/db_helper.rb              |   16 +----------
 server/tests/deltacloud/common.rb              |    3 --
 4 files changed, 21 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/332b2d38/server/bin/deltacloud-db-upgrade
----------------------------------------------------------------------
diff --git a/server/bin/deltacloud-db-upgrade b/server/bin/deltacloud-db-upgrade
index 290dc77..ce6631e 100755
--- a/server/bin/deltacloud-db-upgrade
+++ b/server/bin/deltacloud-db-upgrade
@@ -17,17 +17,8 @@
 require 'rubygems'
 require 'require_relative' if RUBY_VERSION < '1.9'
 
-# Fix loading of SQLite3 driver in JDBC
-#
-if RUBY_PLATFORM == 'java'
-  require 'jdbc/sqlite3'
-  Jdbc::SQLite3.load_driver
-end
-
-# Do not exit
+# Force DB upgrade
 ENV['DB_UPGRADE'] = 'true'
 
 require_relative './../lib/initializers/mock_initialize'
 require_relative './../lib/initializers/database_initialize'
-
-Sequel::Migrator.apply(DATABASE, DATABASE_MIGRATIONS_DIR)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/332b2d38/server/lib/initializers/database_initialize.rb
----------------------------------------------------------------------
diff --git a/server/lib/initializers/database_initialize.rb b/server/lib/initializers/database_initialize.rb
index f7637ca..7ec68aa 100644
--- a/server/lib/initializers/database_initialize.rb
+++ b/server/lib/initializers/database_initialize.rb
@@ -30,18 +30,27 @@ Sequel::Model.plugin :validation_class_methods
 # Enable Sequel migrations extension
 Sequel.extension :migration
 
-# For JRuby we need to different Sequel driver
-#
-sequel_driver = (RUBY_PLATFORM=='java') ? 'jdbc:sqlite:' : 'sqlite://'
-
-# The default sqlite3 database could be override by 'DATABASE_LOCATION'
+# The default sqlite3 database can be overridden with the 'DATABASE_LOCATION'
 # environment variable.
 #
 # For more details about possible values see:
 # http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html
 #
-DATABASE_LOCATION = ENV['DATABASE_LOCATION'] ||
-  "#{sequel_driver}#{File.join(BASE_STORAGE_DIR, 'db.sqlite')}"
+if ENV['DATABASE_LOCATION']
+  DATABASE_LOCATION = ENV['DATABASE_LOCATION']
+else
+  if ENV['RACK_ENV'] == 'test'
+    if RUBY_PLATFORM=='java'
+      DATABASE_LOCATION = 'jdbc:sqlite::memory'
+    else
+      DATABASE_LOCATION = 'sqlite:/'
+    end
+  else
+    sequel_driver = (RUBY_PLATFORM=='java') ? 'jdbc:sqlite:' : 'sqlite://'
+    DATABASE_LOCATION =
+      "#{sequel_driver}#{File.join(BASE_STORAGE_DIR, 'db.sqlite')}"
+  end
+end
 
 if RUBY_PLATFORM == 'java'
   require 'jdbc/sqlite3'
@@ -61,7 +70,9 @@ unless Sequel::Migrator.is_current?(DATABASE, DATABASE_MIGRATIONS_DIR)
   # Do not exit when this intitializer is included from deltacloud-db-upgrade
   # script
   #
-  unless ENV['DB_UPGRADE']
+  if ENV['RACK_ENV'] == 'test' || ENV['DB_UPGRADE']
+    Sequel::Migrator.apply(DATABASE, DATABASE_MIGRATIONS_DIR)
+  else
     warn "WARNING: The database needs to be upgraded. Run: 'deltacloud-db-upgrade' command."
     exit(1)
   end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/332b2d38/server/tests/cimi/db/db_helper.rb
----------------------------------------------------------------------
diff --git a/server/tests/cimi/db/db_helper.rb b/server/tests/cimi/db/db_helper.rb
index 65cca7b..ac44118 100644
--- a/server/tests/cimi/db/db_helper.rb
+++ b/server/tests/cimi/db/db_helper.rb
@@ -1,18 +1,4 @@
-# Memory database
-if RUBY_PLATFORM == 'java'
-  require 'jdbc/sqlite3'
-  Jdbc::SQLite3.load_driver
-  ENV['DATABASE_LOCATION'] = 'jdbc:sqlite::memory:'
-else
-  ENV['DATABASE_LOCATION'] = 'sqlite:/'
-end
-
-ENV['DB_UPGRADE'] = 'true'
-
-require_relative '../../../lib/initializers/database_initialize'
-
-# Apply database migrations:
-Sequel::Migrator.apply(DATABASE, DATABASE_MIGRATIONS_DIR)
+require_relative '../../test_helper'
 
 module Deltacloud
   module DatabaseTestHelper

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/332b2d38/server/tests/deltacloud/common.rb
----------------------------------------------------------------------
diff --git a/server/tests/deltacloud/common.rb b/server/tests/deltacloud/common.rb
index cded956..c31655e 100644
--- a/server/tests/deltacloud/common.rb
+++ b/server/tests/deltacloud/common.rb
@@ -1,8 +1,5 @@
 require_relative '../test_helper.rb'
 
-require_relative File.join('..', '..', 'lib', 'initializers', 'mock_initialize')
-require_relative File.join('..', '..', 'lib', 'initializers', 'frontend_initialize')
-
 Deltacloud.require_frontend! :deltacloud
 
 def check_json_serialization_for(model, sample_id, optional_attrs=[])


Mime
View raw message