lib/dm-rails/storage.rb in dm-rails-1.0.3 vs lib/dm-rails/storage.rb in dm-rails-1.0.4
- old
+ new
@@ -65,17 +65,15 @@
def initialize(name, config)
@name, @config = name.to_sym, config
end
def create
- _create
- puts "[datamapper] Created database '#{database}'"
+ puts create_message if _create
end
def drop
- _drop
- puts "[datamapper] Dropped database '#{database}'"
+ puts drop_message if _drop
end
def database
@database ||= config['database'] || config['path']
end
@@ -90,19 +88,40 @@
def charset
@charset ||= config['charset'] || ENV['CHARSET'] || 'utf8'
end
+ def create_message
+ "[datamapper] Created database '#{database}'"
+ end
+
+ def drop_message
+ "[datamapper] Dropped database '#{database}'"
+ end
+
class Sqlite < Storage
def _create
- return if in_memory?
- # TODO don't to_s the path once a do_sqlite3 gem supports it
- ::DataMapper.setup(name, config.merge('database' => path.to_s))
+ # This is a noop for sqlite
+ #
+ # Both auto_migrate!/auto_upgrade! will create the actual database
+ # if the connection has been setup properly and there actually
+ # are statements to execute (i.e. at least one model is declared)
+ #
+ # DataMapper.setup alone won't create the actual database so there
+ # really is no API to simply create an empty database for sqlite3.
+ #
+ # we return true to indicate success nevertheless
+
+ true
end
def _drop
return if in_memory?
path.unlink if path.file?
+ end
+
+ def create_message
+ "[datamapper] db:create is a noop for sqlite3, use db:automigrate instead (#{database})"
end
private
def in_memory?