deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [4/8] git commit: Remove index creation errors when database is already created
Date Mon, 21 Jan 2013 09:52:12 GMT
Remove index creation errors when database is already created


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

Branch: refs/heads/master
Commit: d39233c595718ed38e8d51f33d47ec227cb0e6d1
Parents: 1b8a5fd
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Wed Jan 16 10:55:21 2013 +0100
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Mon Jan 21 10:51:52 2013 +0100

----------------------------------------------------------------------
 server/lib/db.rb |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/d39233c5/server/lib/db.rb
----------------------------------------------------------------------
diff --git a/server/lib/db.rb b/server/lib/db.rb
index 64cc283..49e6f33 100644
--- a/server/lib/db.rb
+++ b/server/lib/db.rb
@@ -16,22 +16,29 @@ module Deltacloud
   end
 
   def self.initialize_database
+    db = database
 
-    database.create_table?(:providers) {
+    db.create_table?(:providers) {
       primary_key :id
 
       column :driver, :string, { :null => false }
       column :url, :string
-      index [ :url, :driver ]
+      index [ :url, :driver ] if !db.table_exists?(:providers)
     }
 
-    database.create_table?(:entities) {
+    db.create_table?(:entities) {
       primary_key :id
-      foreign_key :provider_id, :providers, { :index => true, :null => false }
+
+      unless db.table_exists?(:entities)
+        foreign_key :provider_id, :providers, { :index => true, :null => false }
+      end
+
       column :created_at, :timestamp
 
       # Base
-      column :model, :string, { :index => true, :null => false, :default => 'entity'
}
+      unless db.table_exists?(:entities)
+        column :model, :string, { :index => true, :null => false, :default => 'entity'
}
+      end
 
       # Map Entity to Deltacloud model
       # (like: Machine => Instance)


Mime
View raw message