Class: ROM::SQL::Migration::Migrator Private
- Inherits:
-
Object
- Object
- ROM::SQL::Migration::Migrator
- Extended by:
- Initializer
- Defined in:
- lib/rom/sql/migration/migrator.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- DEFAULT_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'db/migrate'.freeze
- VERSION_FORMAT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'%Y%m%d%H%M%S'.freeze
- DEFAULT_INFERRER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Schema::Inferrer.new.suppress_errors.freeze
Instance Method Summary collapse
- #auto_migrate!(gateway, schemas, options = EMPTY_HASH, &block) ⇒ Object private
- #create_file(name, version = generate_version, **options) ⇒ Object private
- #generate_version ⇒ Object private
- #migration(&block) ⇒ Object private
- #migration_file_content ⇒ Object private
- #migration_runner(options) ⇒ Object private
- #pending? ⇒ Boolean private
- #run(options = {}) ⇒ Object private
Instance Method Details
#auto_migrate!(gateway, schemas, options = EMPTY_HASH, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rom/sql/migration/migrator.rb', line 68 def auto_migrate!(gateway, schemas, = EMPTY_HASH, &block) diff_finder = SchemaDiff.new(gateway.database_type) changes = schemas.map { |target| empty = SQL::Schema.define(target.name) current = target.with(inferrer.(empty, gateway)) diff_finder.(current, target) }.reject(&:empty?) runner = migration_runner() runner.(changes) end |
#create_file(name, version = generate_version, **options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rom/sql/migration/migrator.rb', line 43 def create_file(name, version = generate_version, **) sequence = [:sequence] ? '%03d' % [:sequence] : nil filename = "#{ version }#{ sequence }_#{ name }.rb" content = [:content] || migration_file_content path = [:path] || self.path dirname = Pathname(path) fullpath = dirname.join(filename) FileUtils.mkdir_p(dirname) File.write(fullpath, content) fullpath end |
#generate_version ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
58 59 60 |
# File 'lib/rom/sql/migration/migrator.rb', line 58 def generate_version Time.now.utc.strftime(VERSION_FORMAT) end |
#migration(&block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 |
# File 'lib/rom/sql/migration/migrator.rb', line 38 def migration(&block) Sequel.migration(&block) end |
#migration_file_content ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
63 64 65 |
# File 'lib/rom/sql/migration/migrator.rb', line 63 def migration_file_content File.read(Pathname(__FILE__).dirname.join('template.rb').realpath) end |
#migration_runner(options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rom/sql/migration/migrator.rb', line 83 def migration_runner() if [:inline] Runner.new(InlineRunner.new(connection)) else counter = 0 writer = Writer.new do |name, content| create_file(name, **, content: content, sequence: counter) counter += 1 end Runner.new(writer) end end |
#pending? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 |
# File 'lib/rom/sql/migration/migrator.rb', line 33 def pending? !Sequel::Migrator.is_current?(connection, path.to_s) end |
#run(options = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/rom/sql/migration/migrator.rb', line 28 def run( = {}) Sequel::Migrator.run(connection, path.to_s, ) end |