Class: Hyrax::DatabaseMigrator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
app/services/hyrax/database_migrator.rb

Overview

Note:

Hyrax::DatabaseMigrator uses Rails’ generator internals to avoid having to re-implement code that knows how to copy migrations only if needed

Hyrax::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 the version of `ActiveRecord::Migration` corresponding to the version of Rails used by the application. This class was added to resolve Hyrax issue #2347

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.copyObject



30
31
32
# File 'app/services/hyrax/database_migrator.rb', line 30

def self.copy
  new.copy
end

.migrations_dirObject



26
27
28
# File 'app/services/hyrax/database_migrator.rb', line 26

def self.migrations_dir
  Hyrax::Engine.root.join('lib', 'generators', 'hyrax', 'templates')
end

.source_rootObject

Note:

This method is required by Rails::Generators::Base



22
23
24
# File 'app/services/hyrax/database_migrator.rb', line 22

def self.source_root
  migrations_dir
end

Instance Method Details

#copyObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/hyrax/database_migrator.rb', line 34

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