lib/hanami/model/migrator/adapter.rb in hanami-model-0.7.0 vs lib/hanami/model/migrator/adapter.rb in hanami-model-1.0.0.beta1
- old
+ new
@@ -24,11 +24,11 @@
# Loads and returns a specific adapter for the given connection.
#
# @since 0.4.0
# @api private
def self.for(configuration) # rubocop:disable Metrics/MethodLength
- connection = connection_for(configuration)
+ connection = Connection.new(configuration)
case connection.database_type
when :sqlite
require 'hanami/model/migrator/sqlite_adapter'
SQLiteAdapter
@@ -38,34 +38,19 @@
when :mysql
require 'hanami/model/migrator/mysql_adapter'
MySQLAdapter
else
self
- end.new(connection, configuration)
+ end.new(connection)
end
- class << self
- private
-
- # @since 0.7.0
- # @api private
- def connection_for(configuration)
- Sequel.connect(
- configuration.url
- )
- rescue Sequel::AdapterNotFound
- raise MigrationError.new("Current adapter (#{configuration.adapter.type}) doesn't support SQL database operations.")
- end
- end
-
# Initialize an adapter
#
# @since 0.4.0
# @api private
- def initialize(connection, configuration)
- @connection = Connection.new(connection)
- @schema = configuration.schema
+ def initialize(connection)
+ @connection = connection
end
# Create database.
# It must be implemented by subclasses.
#
@@ -126,10 +111,12 @@
# @api private
attr_reader :connection
# @since 0.4.0
# @api private
- attr_reader :schema
+ def schema
+ connection.schema
+ end
# Returns a database connection
#
# Given a DB connection URI we can connect to a specific database or not, we need this when creating
# or droping a database. Important to notice that we can't always open a _global_ DB connection,