On 01/15/2013 10:08 AM, [email protected] wrote:
> Hi,
>
> This is an initial attempt to replace DataMapper with more ligher
> ORM (Sequel).
> The main reason of doing this is lack of DataMapper RPM's in distributions
> we want to support.
>
> Pros:
>
> - Less dependencies (sequel + sqlite3)
> - More performance tunning (sequel allows to modify SQL queries to get less
> queries)
> - Caching (not interesting right now, but might be in future)
>
> Cons:
>
> - No automigration (you will need to run fixture reset rake task)
>
> Let me know what you think :)
>
> If you want try this patch, please reset the 'mock' fixtures and DB using:
>
> 'rake mock:fixtures:reset'
>
> Also please run 'bundle update' to get rid of DataMapper and install Sequel.
>
> Let me know what you think :)
>
> -- Michal
>
Michal,
This looks great.
I did some minimal testing and response time seems faster.
I tried creating a macine and machine_templates. I was not able
to create the machine_templates but that is very likely because I
was not doing it correctly. Can you please pass along an example
of how to create a machine_template?
I just have a couple minor nits/questions about the code in:
[PATCH core 1/3] CIMI: Replaced DataMapper with Sequel ORM
Please see "JoeV:" below for my comments.
Hope this helps!
Joe
- - -
diff --git a/server/lib/db.rb b/server/lib/db.rb
index 567b356..64cc283 100644
--- a/server/lib/db.rb
+++ b/server/lib/db.rb
@@ -4,27 +4,74 @@ module Deltacloud
ENV['RACK_ENV'] == 'test' || ENV['DELTACLOUD_NO_DATABASE']
end
- unless test_environment?
- require 'data_mapper'
- require_relative './db/provider'
- require_relative './db/entity'
- require_relative './db/machine_template'
- require_relative './db/address_template'
- require_relative './db/volume_configuration'
- require_relative './db/volume_template'
- end
+ require 'sequel' unless test_environment?
+ require 'logger'
+
+ DATABASE_LOCATION = ENV['DATABASE_LOCATION'] ||
+ 'sqlite://'+File.join('/', 'var', 'tmp',
"deltacloud-mock-#{ENV['USER']}", 'db.sqlite')
- DATABASE_LOCATION = ENV['DATABASE_LOCATION'] || File.join('/', 'var',
'tmp', "deltacloud-mock-#{ENV['USER']}", 'db.sqlite')
+ def self.database(opts={})
+ opts[:logger] = ::Logger.new($stdout) if ENV['API_VERBOSE']
+ @db ||= Sequel.connect(DATABASE_LOCATION, opts)
+ end
JoeV: Question/nit:
JoeV:
JoeV: Would it make more sense to allow DATABASE_LOCATION to specify
JoeV: the path to db.sqlite but still use "db.sqlite" at the end of the
path?
JoeV: Question/nit:
JoeV:
JoeV: Does sequel require the other files which "rake mock:fixtures:reset"
JoeV: populates in DATABASE_LOCATION or just "db.sqlite" ? If so:
JoeV: doesn't the Rakefile need to be updated to only populate
JoeV: DATABASE_LOCATION or just "db.sqlite" ?
def self.initialize_database
- DataMapper::Logger.new($stdout, :debug) if ENV['API_VERBOSE']
- dbdir = File::dirname(DATABASE_LOCATION)
- FileUtils::mkdir(dbdir) unless File::directory?(dbdir)
- DataMapper::setup(:default, "sqlite://#{DATABASE_LOCATION}")
- DataMapper::finalize
- DataMapper::auto_upgrade!
+
+ database.create_table?(:providers) {
+ primary_key :id
+
+ column :driver, :string, { :null => false }
+ column :url, :string
+ index [ :url, :driver ]
+ }
+
+ database.create_table?(:entities) {
+ primary_key :id
+ foreign_key :provider_id, :providers, { :index => true, :null =>
false }
+ column :created_at, :timestamp
+
JoeV: Question/nit:
JoeV: Why the "?" postfix for create_table"?" ?
JoeV: Does it return true on success?