Class: QaServer::DatabaseMigrator

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

Overview

Note:

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

QaServer::DatabaseMigrator is responsible for copying QaServer’s required database migrations into applications. Rails engines typically use the built-in ‘ENGINE_NAME:install:migrations` task to handle this; instead QaServer 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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.copyObject



28
29
30
# File 'app/services/qa_server/database_migrator.rb', line 28

def self.copy
  new.copy
end

.migrations_dirObject



24
25
26
# File 'app/services/qa_server/database_migrator.rb', line 24

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

.source_rootObject

Note:

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



20
21
22
# File 'app/services/qa_server/database_migrator.rb', line 20

def self.source_root
  migrations_dir
end

Instance Method Details

#copyObject

def copy

# QA Server'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. QA Server skips these conflicts.
migrations.each do |filename|
  migration_template filename,
                     "db/migrate/#{parse_basename_from(filename)}",
                     migration_version: migration_version,
                     skip: true
end

end



45
46
47
48
49
50
51
# File 'app/services/qa_server/database_migrator.rb', line 45

def copy
  migrations.each do |filename|
    migration_template filename,
                       "db/migrate/#{parse_basename_from(filename)}",
                       migration_version: migration_version
  end
end