You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2013/03/07 12:22:16 UTC
[8/8] git commit: Remove global constants DATABASE and
DATABASE_LOCATION
Updated Branches:
refs/heads/master d53a126c0 -> e2fa1a339
Remove global constants DATABASE and DATABASE_LOCATION
Also streamlines how we create/retrieve the current DB
TrackedAt: http://tracker.deltacloud.org/patch/4c4617b0e7fb773edbb1f87040462ae61ad45d8a
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/e2fa1a33
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/e2fa1a33
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/e2fa1a33
Branch: refs/heads/master
Commit: e2fa1a3398ae233dbdf43c00a2f90d81bdf79596
Parents: 332b2d3
Author: David Lutterkort <lu...@redhat.com>
Authored: Wed Mar 6 18:09:17 2013 -0800
Committer: Michal fojtik <mf...@redhat.com>
Committed: Thu Mar 7 12:17:19 2013 +0100
----------------------------------------------------------------------
server/lib/db.rb | 16 ++++++++++------
server/lib/initializers/database_initialize.rb | 17 +++++++----------
2 files changed, 17 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e2fa1a33/server/lib/db.rb
----------------------------------------------------------------------
diff --git a/server/lib/db.rb b/server/lib/db.rb
index 0cd18e4..7371438 100644
--- a/server/lib/db.rb
+++ b/server/lib/db.rb
@@ -15,19 +15,23 @@
module Deltacloud
- def self.database(opts={})
+ def self.connect(location)
if ENV['API_VERBOSE']
if Deltacloud.respond_to? :config
- opts[:logger] = Deltacloud.config[:cimi].logger
+ logger = Deltacloud.config[:cimi].logger
else
- opts[:logger] = ::Logger.new($stdout)
+ logger = ::Logger.new($stdout)
end
end
- @db ||= Sequel.connect(DATABASE_LOCATION, opts)
+ @db = Sequel.connect(location, :logger => logger)
end
- def self.initialize_database
- db = database
+ def self.database
+ @db
+ end
+
+ def self.initialize_database(location)
+ db = connect(location)
db.create_table?(:providers) {
primary_key :id
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e2fa1a33/server/lib/initializers/database_initialize.rb
----------------------------------------------------------------------
diff --git a/server/lib/initializers/database_initialize.rb b/server/lib/initializers/database_initialize.rb
index 7ec68aa..13f2904 100644
--- a/server/lib/initializers/database_initialize.rb
+++ b/server/lib/initializers/database_initialize.rb
@@ -36,19 +36,16 @@ Sequel.extension :migration
# For more details about possible values see:
# http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html
#
-if ENV['DATABASE_LOCATION']
- DATABASE_LOCATION = ENV['DATABASE_LOCATION']
-else
+unless location = ENV['DATABASE_LOCATION']
if ENV['RACK_ENV'] == 'test'
if RUBY_PLATFORM=='java'
- DATABASE_LOCATION = 'jdbc:sqlite::memory'
+ location = 'jdbc:sqlite::memory'
else
- DATABASE_LOCATION = 'sqlite:/'
+ location = 'sqlite:/'
end
else
sequel_driver = (RUBY_PLATFORM=='java') ? 'jdbc:sqlite:' : 'sqlite://'
- DATABASE_LOCATION =
- "#{sequel_driver}#{File.join(BASE_STORAGE_DIR, 'db.sqlite')}"
+ location = "#{sequel_driver}#{File.join(BASE_STORAGE_DIR, 'db.sqlite')}"
end
end
@@ -57,7 +54,7 @@ if RUBY_PLATFORM == 'java'
Jdbc::SQLite3.load_driver
end
-DATABASE = Deltacloud::initialize_database
+database = Deltacloud::initialize_database(location)
# Detect if there are some pending migrations to run.
# We don't actually run migrations during server startup, just print
@@ -66,12 +63,12 @@ DATABASE = Deltacloud::initialize_database
DATABASE_MIGRATIONS_DIR = File.join(File.dirname(__FILE__), '..', '..', 'db', 'migrations')
-unless Sequel::Migrator.is_current?(DATABASE, DATABASE_MIGRATIONS_DIR)
+unless Sequel::Migrator.is_current?(database, DATABASE_MIGRATIONS_DIR)
# Do not exit when this intitializer is included from deltacloud-db-upgrade
# script
#
if ENV['RACK_ENV'] == 'test' || ENV['DB_UPGRADE']
- Sequel::Migrator.apply(DATABASE, DATABASE_MIGRATIONS_DIR)
+ Sequel::Migrator.apply(database, DATABASE_MIGRATIONS_DIR)
else
warn "WARNING: The database needs to be upgraded. Run: 'deltacloud-db-upgrade' command."
exit(1)