lib/rom/sql/migration/migrator.rb in rom-sql-1.3.5 vs lib/rom/sql/migration/migrator.rb in rom-sql-2.0.0.beta1
- old
+ new
@@ -1,9 +1,11 @@
require 'pathname'
require 'rom/types'
require 'rom/initializer'
+require 'rom/sql/migration'
+require 'rom/sql/migration/inline_runner'
module ROM
module SQL
module Migration
# @api private
@@ -50,9 +52,24 @@
end
# @api private
def migration_file_content
File.read(Pathname(__FILE__).dirname.join('template.rb').realpath)
+ end
+
+ # @api private
+ def diff(gateway, inferrer, target)
+ empty = SQL::Schema.define(target.name)
+ current = target.with(inferrer.(empty, gateway))
+
+ SchemaDiff.new.(current, target)
+ end
+
+ def auto_migrate!(gateway, schemas)
+ runner = InlineRunner.new(gateway)
+ inferrer = ROM::SQL::Schema::Inferrer.new.suppress_errors
+ changes = schemas.map { |schema| diff(gateway, inferrer, schema) }.reject(&:empty?)
+ runner.(changes)
end
end
end
end
end