Class: Hyrax::DatabaseMigrator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Hyrax::DatabaseMigrator
- Includes:
- ActiveRecord::Generators::Migration
- Defined in:
- app/services/hyrax/database_migrator.rb
Overview
Note:
DatabaseMigrator uses Rails’ generator internals to avoid having to re-implement code that knows how to copy migrations only if needed.
Note:
This class was added to resolve Hyrax issue #2347
DatabaseMigrator is responsible for copying Hyrax‘s required database migrations into applications.
Rails engines typically use the built-in [ENGINE_NAME]:install:migrations
task to handle this; instead Hyrax follows the practice used by Devise
to dynamically subclass migrations with he version of ActiveRecord::Migration
corresponding to the version of Rails used by the application.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.copy ⇒ Object
35 36 37 |
# File 'app/services/hyrax/database_migrator.rb', line 35 def self.copy new.copy end |
.migrations_dir ⇒ Object
31 32 33 |
# File 'app/services/hyrax/database_migrator.rb', line 31 def self.migrations_dir Hyrax::Engine.root.join('lib', 'generators', 'hyrax', 'templates') end |
.source_root ⇒ Object
Note:
This method is required by Rails::Generators::Base
27 28 29 |
# File 'app/services/hyrax/database_migrator.rb', line 27 def self.source_root migrations_dir end |
Instance Method Details
#copy ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/services/hyrax/database_migrator.rb', line 39 def copy # Hyrax's migrations changed between 2.0.0 and subsequent versions, so the # migration comparison algorithm decides that those older migrations are a # source of conflict. Default Rails behavior here is to abort and # explicitly instruct the user to try again with either the `--skip` or # `--force` option. Hyrax skips these conflicts. migrations.each do |filename| migration_template filename, "db/migrate/#{parse_basename_from(filename)}", migration_version: migration_version, skip: true end end |