class DbSeed::InstallGenerator

Installs PaperTrail in a rails app.

Constants

MYSQL_ADAPTERS

Class names of MySQL adapters.

  • `MysqlAdapter` - Used by gems: `mysql`, `activerecord-jdbcmysql-adapter`.

  • `Mysql2Adapter` - Used by `mysql2` gem.

Public Class Methods

next_migration_number(dirname) click to toggle source
# File lib/generators/db_seed/install_generator.rb, line 25
def self.next_migration_number(dirname)
  ::ActiveRecord::Generators::Base.next_migration_number(dirname)
end

Public Instance Methods

create_migration_file() click to toggle source
# File lib/generators/db_seed/install_generator.rb, line 21
def create_migration_file
  add_seed_migration("create_active_record_seed")
end

Protected Instance Methods

add_seed_migration(template) click to toggle source
# File lib/generators/db_seed/install_generator.rb, line 31
def add_seed_migration(template)
  migration_dir = File.expand_path("db/migrate")
  if self.class.migration_exists?(migration_dir, template)
    ::Kernel.warn "Migration already exists: #{template}"
  else
    migration_template(
        "#{template}.rb.erb",
        "db/migrate/#{template}.rb",
        migration_version: migration_version
    )
  end
end

Private Instance Methods

migration_version() click to toggle source
# File lib/generators/db_seed/install_generator.rb, line 46
def migration_version
  major = ::ActiveRecord::VERSION::MAJOR
  if major >= 5
    "[#{major}.#{::ActiveRecord::VERSION::MINOR}]"
  end
end