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/02/19 10:11:23 UTC
[4/5] git commit: CIMI: Print warning for pending migrations
CIMI: Print warning for pending migrations
We don't want to run any migrations automatically during
Deltacloud server boot time, to give users chance to backup
data, etc.
This patch will provide a nice warning message if you start
Deltacloud and you have some pending migrations to run.
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/fd4e4aff
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/fd4e4aff
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/fd4e4aff
Branch: refs/heads/master
Commit: fd4e4affbc64d1f0a7d8f594e21de2b6c5a6c586
Parents: 165922f
Author: Michal Fojtik <mf...@redhat.com>
Authored: Mon Feb 18 16:19:27 2013 +0100
Committer: Michal fojtik <mf...@redhat.com>
Committed: Tue Feb 19 10:10:57 2013 +0100
----------------------------------------------------------------------
server/bin/deltacloud-db-upgrade | 18 +++++++++++-------
server/lib/initializers/database_initialize.rb | 19 ++++++++++++++++++-
2 files changed, 29 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fd4e4aff/server/bin/deltacloud-db-upgrade
----------------------------------------------------------------------
diff --git a/server/bin/deltacloud-db-upgrade b/server/bin/deltacloud-db-upgrade
index 2698350..5b37bbb 100755
--- a/server/bin/deltacloud-db-upgrade
+++ b/server/bin/deltacloud-db-upgrade
@@ -1,13 +1,17 @@
#!/usr/bin/env ruby
-ENV['API_VERBOSE'] = 'true'
+require 'rubygems'
-load File.join(File.dirname(__FILE__), '..', 'lib', 'db.rb')
+require 'require_relative' if RUBY_VERSION < '1.9'
-# Initialize the database
-#
-db = Deltacloud.initialize_database
+require_relative './../lib/initializers/mock_initialize'
+require_relative './../lib/initializers/database_initialize'
-# Apply the migrations
+# The DATABASE_UPGRADE constant is set to true if we have discovered
+# pending migrations in DATABASE_MIGRATIONS_DIR.
#
-Sequel::Migrator.apply(db, File.join(File.dirname(__FILE__), '..', 'db', 'migrations'))
+
+if DATABASE_UPGRADE
+ puts "Upgrading database schema to the latest version..."
+ Sequel::Migrator.apply(DATABASE, DATABASE_MIGRATIONS_DIR)
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fd4e4aff/server/lib/initializers/database_initialize.rb
----------------------------------------------------------------------
diff --git a/server/lib/initializers/database_initialize.rb b/server/lib/initializers/database_initialize.rb
index 32badb2..ae9d247 100644
--- a/server/lib/initializers/database_initialize.rb
+++ b/server/lib/initializers/database_initialize.rb
@@ -12,6 +12,9 @@ require_relative '../db'
#
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://'
@@ -25,4 +28,18 @@ sequel_driver = (RUBY_PLATFORM=='java') ? 'jdbc:sqlite:' : 'sqlite://'
DATABASE_LOCATION = ENV['DATABASE_LOCATION'] ||
"#{sequel_driver}#{File.join(BASE_STORAGE_DIR, 'db.sqlite')}"
-Deltacloud::initialize_database
+DATABASE = Deltacloud::initialize_database
+
+# Detect if there are some pending migrations to run.
+# We don't actually run migrations during server startup, just print
+# a warning to console
+#
+
+DATABASE_MIGRATIONS_DIR = File.join(File.dirname(__FILE__), '..', '..', 'db', 'migrations')
+
+unless Sequel::Migrator.is_current?(DATABASE, DATABASE_MIGRATIONS_DIR)
+ warn "WARNING: The database needs to be upgraded. Run: 'deltacloud-db-upgrade' command."
+ DATABASE_UPGRADE = true
+else
+ DATABASE_UPGRADE = false
+end